I have a collection named network_groups and another collection named network_objects.
Each network group can contain multiple network_objects elements and group_objects( which are elements within the network_groups collection) as well.
Here is an example of each:
- item of network-groups:
{
_id: ObjectId('...'),
name: "CyM_PC",
description:"CyM_PC (Outside, Inside)",
network_objects: [
"IN03PGSUR",
"IN04PGSUR",
"IN05PGSUR"
],
group_objects: [
"Other_Users"
]
}
- item of network-objects:
{
_id: ObjectId('...'),
name: "IN03PGSUR",
description: "Created during migration"
}
The thing is inside group_objects there could be other network_groups items with network_groups inside and this could go on for a few layers.
I would like to extract all network_objects in the nested network_groups, so I have made a loopup query:
{
"$lookup": {
"from": "network_groups",
"localField": "group_objects",
"foreignField": "name",
"pipeline": [
{
"$lookup": {
"from": "network_groups",
"localField": "group_objects",
"foreignField": "name",
"as": "networks_inside"
}
}
],
"as": "networks"
}
}
But this just covers 2 layers of nesting. I would like to keep going as long as there is a network_groups item with group_objects inside.
Is there a way to perform such an iterative query.
Thanks