I have a collection where each document contains 2 arrays of documents as below.
{
all_users:[
{
id:1,
name:"A"
},
{
id:2,
name:"B"
},
{
id:3,
name:"C"
}
]
selected_users:[
{
id:1,
name:"A"
},
{
id:2,
name:"B"
}
]
}
Is it possible to merge the 2 arrays by adding a field selected and assigning a value to it based on whether the name of the user is present in a document in the selected_users array as follows.
{
all_users:[
{
id:1,
name:"A",
selected:"yes"
},
{
id:2,
name:"B",
selected:"yes"
},
{
id:3,
name:"C",
selected:"no"
}
]
}
I want to check by id or name since the documents may contain additional fields. I can't figure out how to achieve this.