在MongoDB中查找第n级嵌套子文档所有者

时间:2019-09-19 17:27:50

标签: arrays database mongodb nested subdocument

我很难找到嵌套在第n级的子文档的所有者。

这是建议的文档结构。

{
  "_id": "foo_l0",
  "subdocs" : [
    {
      "_id" : "foo_0_l1"
    },
    {
      "_id" : "foo_1_l1",
      "subdocs": [
        {
          "_id": "foo_0_l2",
          "subdocs": [
           {
             "_id": "foo_0_ln",
             "subdocs" : []
           }
          ]
        },
        {
          "_id": "foo_1_l2",
          "subdocs": [
           {
             "_id": "foo_0_ln",
             "subdocs": []
           }
          ]
        }
      ]
    }
  ]
}

我希望能够使用嵌套在第n级的foo_0_ln找到foo_l0。 (n未知)

换句话说,不管子文档嵌套在所有者文档中有多深,都可以使用其中一个子文档的id查询MongoDB吗?

0 个答案:

没有答案
相关问题