Trees in CouchDB
I'm new to CouchDB and have a question.
I'm saving messages with the ID of the parent message as an attribute. A message can also have a childMessage as parent, so it looks like a tree.
How can i query all childs including the开发者_开发问答 childs of the childs?
Thank you
This is the commonly used method when dealing with hierarchical data: http://probablyprogramming.com/2008/07/04/storing-hierarchical-data-in-couchdb/
CouchDB works best with the de-normalized data. You should consider de-normalizing your data as much as possible. Maybe you may store the whole tree as a single document?
E.g.:
{
"msg":"Parent message",
"children":[
{
"msg":"sub message 1"
},
{
"msg":"sub message 2",
"children":[
{
"msg":"sub sub message 1"
}
]
}
]
}
精彩评论