CouchDB 中的树

发布于 2024-10-08 13:09:42 字数 136 浏览 0 评论 0原文

我是 CouchDB 新手,有一个问题。

我正在使用父消息的 ID 作为属性来保存消息。 消息还可以有一个 childMessage 作为父级,因此它看起来像一棵树。

我如何查询所有孩子,包括孩子的孩子?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦太阳 2024-10-15 13:09:42

CouchDB 最适合处理非规范化数据。您应该考虑尽可能地对数据进行反规范化。也许您可以将整个树存储为单个文档?

例如:

{
  "msg":"Parent message",
  "children":[
    {
       "msg":"sub message 1"
    },
    {
       "msg":"sub message 2",
       "children":[
         {
           "msg":"sub sub message 1"
         }
       ]
    }
  ]
}

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"
         }
       ]
    }
  ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文