mongodb - mongoDB最优模式设计
问题描述
该页面有 2 个链接,查看文章和查看我的收藏文章。我想知道我应该在哪里捕获 MongoDB 模式中最喜欢的文章 ObjectID。当用户单击“查看我的收藏夹”链接时,在用户模式或文章模式中?这是我的用户和文章的 MongoDB 模式。提前非常感谢,非常感谢您的评论。谢谢
//Article Schema
const articleSchema = new mongoose.Schema({
title:{
type: String,
required: "Title is required",
trim: true,
},
bodytext:{
type: String,
required: "Body is required"
},
category:{type:ObjectID,ref:"Category"},
favourite:[{type:ObjectID,ref:"User"}],
date: {
type:Date,
default: Date.now
},
},
{ timestamps: true });
module.exports = mongoose.model("Article", articleSchema);
//User Schema
const userSchema = mongoose.Schema({
displayname: {type: String, trim: true},
favourite:[{type:ObjectID,ref:"Article"}],
},{ timestamps: true });
module.exports = mongoose.model("User", userSchema);
解决方案
推荐阅读
- symfony - 学说 query_cache 自动过期
- prolog - Prolog 办公室拼图
- java - 如何打印非静态方法
- liquibase - DatabaseChangeLog 不记录 exectype 不是“EXECUTED”的行
- excel - 每个查找值在 Excel 中求和行数
- vb.net - 是否可以在表单 B(VB.NET)中显示表单 A 中的对象?
- c - 在 GTK 中使用多线程?
- amazon-web-services - 使用 Amazon API Gateway 和 CloudFront 缩短响应时间
- r - 在ggplot2中的特定位置放置背景图像并进行测量
- google-cloud-platform - GCE on Container + CloudSQL