【问题标题】:MongoDB Tree with Array of Ancestors design具有祖先数组设计的 MongoDB 树
【发布时间】:2015-01-24 03:07:01
【问题描述】:

我有一个关于如何在 MongoDB 中设计祖先树的问题。

例如,如果我们有这个:

{ "_id" : "ACL", "ancestors" : [ ], "parent" : null }
{ "_id" : "apps", "ancestors" : [ "ACL" ], "parent" : "ACL" }
{ "_id" : "3222", "ancestors" : [ "ACL", "apps" ], "parent" : "apps" }
{ "_id" : "1223", "ancestors" : [ "ACL", "apps" ], "parent" : "apps" }

这意味着我们有一棵这样的树

       ACL      
        |       
      Apps      
     /    \     
   3222  1223   

我想在每个节点下都有一个“用户”节点。但是,鉴于 _id 必须是唯一的,我不能这样做。

       ACL      
        |       
      Apps      
     /    \     
   3222  1223   
  /         \   
users      users

你会如何解决这个问题?

编辑:我在这里阅读了关于 MongoDB 的模型树信息: http://docs.mongodb.org/manual/tutorial/model-tree-structures/

【问题讨论】:

    标签: mongodb tree


    【解决方案1】:

    我认为没有办法处理你的情况,除非你不使用“_id”作为唯一的树节点,你可以考虑这个架构:

    { "_id" : ["unique guid":xxx, "tree node": "users"], "ancestors" : [ ], "parent" : null }
    { "_id" : ["unique guid":xxx, "tree node": "users"], "ancestors" : [ "ACL" ], "parent" : "ACL" }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多