- Joined
- Aug 27, 2022
- Messages
- 1
- Reaction score
- 0
I created a categories document in mongodb like this
While Thanking the forum, i had a request a aggregate command to reach this Json
In all records, the children field needs to be identified.
I will be very grateful for your answers.
JSON:
{
id: 1,
name: 'digital',
parent: null
},
{
id: 3,
name: 'tv',
parent: 1
},
{
id: 4,
name: 'samsung',
parent: 3
},
{
id: 2,
name: 'kitchen',
parent: null
},
{
id: 5,
name: 'electronic',
parent: 2
}
While Thanking the forum, i had a request a aggregate command to reach this Json
JSON:
[
{
"id": 1,
"name": "digital",
"children":[
{
"id": 3
"name": "tv",
"children": [
{
"id": 4,
"name": "samsung",
"children": []
}
]
}
]
},
{
"id": 2,
"name": "kitchen",
"children": [
{
"id": 5,
"name": "electronic",
"children": []
}
]
}
]
In all records, the children field needs to be identified.
I will be very grateful for your answers.