MongoDB と Mongoose にコメント ツリーを格納する最良の方法は何でしょうか? 現在、私はこれを持っています:
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
});
しかし、これはトップ レベルのコメント + 1 つ以上のレベルのコメントにのみ適しているようです。ReplySchema
内部で使用できないことは確かですReplySchema
。