【发布时间】:2015-04-22 08:41:31
【问题描述】:
在 MongoDB 中存储嵌套集(如 cmets 树)的最佳实践是什么?
我的意思是,每条评论都可以有一个父评论和一个children-cmets(答案)。
像这样存储它们:
{
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 评论的帖子”。
【问题讨论】:
标签: mongodb