1

I am having trouble trying to find the owner of a sub-document nested at the nth level.

Here's the proposed document structure.

{
  "_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": []
           }
          ]
        }
      ]
    }
  ]
}

I want to be able to find foo_l0, using foo_0_ln which is nested at the nth level. (n is unkown)

In other words, is it possible to query MongoDB using the id of one of the sub-documents no matter how deep they're nested inside the owner document?

Turismo98
  • 149
  • 1
  • 1
  • 13
  • 1
    Looks to me that it is what you are looking for: [How to find MongoDB field name at arbitrary depth](https://stackoverflow.com/questions/31197652/how-to-find-mongodb-field-name-at-arbitrary-depth) – Johan Durán Sep 19 '19 at 18:00

0 Answers0