Trees in CouchDB

醉酒当歌 提交于 2019-12-21 20:59:05

问题


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


回答1:


This is the commonly used method when dealing with hierarchical data: http://probablyprogramming.com/2008/07/04/storing-hierarchical-data-in-couchdb/




回答2:


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"
         }
       ]
    }
  ]
}


来源:https://stackoverflow.com/questions/4512298/trees-in-couchdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!