在MongoDB中存储嵌套集(如注释树)的最佳实践是什么?
我的意思是,每个评论都可以有父评论和孩子评论(答案).
像这样存储它们:
{ title: "Hello", body: "Please comment me!", comments: [ { author: "Peter", text: "Hi there", answers: [ { author: "Peter", text: "Hi there", answers: [ { author: "Ivan", text: "Hi there" }, { author: "Nicholas", text: "Hi there" } ] }, { author: "Ivan", text: "Hi there" }, { author: "Nicholas", text: "Hi there" }, ] }, { author: "Ivan", text: "Hi there" }, { author: "Nicholas", text: "Hi there" }, ] }
并不酷,因为我们不能,例如,在没有map/reduce的情况下,请求"所有被Peter评论的帖子".