MongoDB:从深层嵌套的子文档中获取文档ID

时间:2016-12-21 18:50:10

标签: mongodb mongoose database

我已将Directed Acyclic Graph存储为如下文档:

{
   "_id" : ObjectId("58595041cfdc46100f92a985"),
   "modelType" : "Graph",
   "name" : "Graph 1",
   "connections" : [
        {
           "id" : ObjectId("5859504dcfdc46100f92a986"),
           "name" : "node 1",
           "connections" : [
               {
                  "id" : ObjectId("58595057cfdc46100f92a987"),
                  "name" : "node 2",  // shows that node 1 is connected to node 2
                  "connections" : [
                      {
                         "id" : ObjectId("58595057cfdc46100f92a987"),
                         "name" : "node 3", // shows that node 2 is connected to node 3

                      },
                      {
                         "id" : ObjectId("5859506ccfdc46100f92a988"),
                         "name" : "node 4"  // shows that node 2 is connected to node 4
                      }
                  ]
               },
               {
                  "id" : ObjectId("5859506ccfdc46100f92a988"),
                  "name" : "node 3"   // shows that node 1 is connected to node 3
               }
           ]
      }
   ]
}

现在,给定任何连接ID,我想知道它属于哪个图。

我认为这可以通过查询以递归方式查找文档来查找具有指定文档ID的子文档来解决。

请提供一些有关如何编写查询以从连接ID获取GraphID的信息。

0 个答案:

没有答案
相关问题