Quelles sont les meilleures pratiques pour stocker des ensembles imbriqués (comme des arbres de commentaires) dans MongoDB?Ensembles imbriqués MongoDB
Je veux dire, chaque commentaire peut avoir un commentaire de parent et les enfants commentaires (réponses).
les stocker comme ceci:
{
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" },
]
}
est pas cool, parce que nous ne pouvons pas, par exemple, demander "tous les post qui sont commentées par Peter" sans map/reduce.