mongoose多对多关系

我是初学Node.JS和Mongoose的程序员。 到目前为止,我已经创build了一个非常简单的博客3种模式 – 文章,用户,类别和一切工作正常。 现在我想创build评论。 所以我希望每一个用户都能够有一个曼尼的评论,每一篇文章也都能够有一个曼尼的评论。 我怎么能做到这一点,我怎样才能代表控制器中的逻辑互相交互:

let articleSchema = mongoose.Schema ( { author: {type: ObjectId, ref: 'User'}, title: {type: String, required: true }, content: {type: String, required: true }, category: {type: ObjectId, ref: 'Category', required: true}, date: {type: Date, default: Date.now() }, } ); let userSchema = mongoose.Schema( { email: {type: String, required: true, unique: true}, passwordHash: {type: String, required: true}, fullName: {type: String, required: true}, salt: {type: String, required: true}, articles: [{type: ObjectId, ref: 'Article'}], roles: [{type: ObjectId, ref: 'Role'}] } ); let categorySchema = mongoose.Schema ( { name: {type: String, required:true}, articles: [{type: ObjectId, ref: 'Article'}] } ); 

Solutions Collecting From Web of "mongoose多对多关系"