What would be the best way to store comments trees in MongoDB and Mongoose? Currently I have this:
CommentableSchema = new Schema({
...
});
ReplySchema = new Schema({
userId: Number,
'body': String,
createdAt: Date,
updatedAt: Date
});
CommentSchema = new Schema({
commentable: CommentableSchema,
userId: Number, // users are NOT stored in MongoDB
subject: String,
'body': String,
createdAt: Date,
updatedAt: Date,
replies: [ReplySchema],
length: Number // comment + all replies
});
But this seems to be suitable only for top level comment + 1 more level of comments. I am fairly certain that I can not use ReplySchema
inside ReplySchema
.
From the oficial manual, i guess you'll find more than all your answers here ( :
http://docs.mongodb.org/manual/tutorial/model-tree-structures/
good luck
You might look at these links:
http://groups.google.com/group/mongodb-user/browse_thread/thread/3f35c3fb28891b52
http://blog.fiesta.cc/post/11319522700/walkthrough-mongodb-data-modeling
Also, are you sure a recursive schema isn't supported? You may check this link: