Let's say I am building a discussion forum using Node.js, and mongoose. A user can have multiple forums, and a forum can have multiple comments. A user can also invite other users to join a forum too. Thus, my question is about the model design either using reference or embedded document !
If I go with embedded document, It would look like:
var Comment = new Schema({ ... });
var Forum = new Schema({
title: {type: String},
content: {type: String},
comments: [Comment],
attendees: [User]
});
var User = new Schema({
name: {type: String},
email: {type: String},
forums: [Forum]
});
var Account = mongoose.model('Account', User);
Using the above design, I struggled with: when a user adds a comment to a forum, and that forum is in my forums, I don't think I would be able to get update of a new comment in my forum list. Do I ? Do you know how to get the embedded document to work in this case?
Thus, I was thinking of using reference in mongoose. In this case, I will have two collections: Account, and Forum. Adding a new comment to a forum is not a problem in this case. Am I right?
Would reference be better than embedded document for this app?
Thanks in advance,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…