首页 > 解决方案 > 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);
 

标签: mongodb

解决方案


推荐阅读