I have a aggregate statement that returns following result. I want to change this result-1 to result-2. How can I make do it? Please teach me that pipeline.
result-1
[
{
_id: "sdfsdfasdasdfasdf",
name: "Robot James"
friends: [
]
}
{
_id: "sdfsdfasdasdfasdf",
name: "John Wu"
friends: [
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1"
friends: [
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1-1"
friends: [
]
},
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1-2"
friends: [
]
}
]
}
]
}
]
Here, Robot James and John Wu are my friends, Robot James hasn’t any friends, but John wu has friends.
If my friends has their friends, I want to add their friends to my friends list, but instead of him, like following,.
[
{
_id: "sdfsdfasdasdfasdf",
name: "Robot James"
friends: [
]
}
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1"
friends: [
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1-1"
friends: [
]
},
{
id: "asdfasdfasdfaadsf",
name: "John Wu-1-2"
friends: [
]
}
]
}
]