Hi @Matheus_Souza and welcome in the MongoDB Community
!
I would do an aggregation pipeline like this. Maybe there is a more simple solution but… I like it
!
[
{
'$project': {
'orders': {
'$map': {
'input': '$orders',
'in': {
'_id': '$$this'
}
}
}
}
}, {
'$merge': {
'into': 'coll',
'on': '_id',
'whenMatched': 'merge',
'whenNotMatched': 'fail'
}
}
]
I tested on a couple of docs and I have the correct result in the end. I’m basically overwriting the orders field.
Cheers,
Maxime.