N
N
nskaskyo2021-12-09 20:22:02
MongoDB
nskaskyo, 2021-12-09 20:22:02

How to aggregate nesting greater than 2 in MongoDB?

Good afternoon.

There are three tables:

[
      {
          _id: '1111111111'
          galaxyNumber: 1
          systems: [
            '2222222222'
          ]
      }
  ]

[
      {
        _id: '2222222222'
          systemNumber: 1
          planets: [
            '3333333333'
          ]   
      }
  ]

[
      {
          _id: '333333333'
          name: 'Земля'
      }
  ]


a want to get:
[
      {
        _id: '1111111111'
        galaxyNumber: 1
        systems: [
            {
                _id: '2222222222'
                  systemNumber: 1
                  planets: [
                    {
                        _id: '333333333'
                        name: 'Земля'
                    }
                  ]   
              }
        ] 
      }
  ]

to make it all look like they are hierarchically embedded.

I get the first level of $lookup. Then I break $unwind the systems field, but I can’t get to planets in any way to do a lookup for it.

Help me figure out what is needed. $match, $pipeline or whatever

Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question