I have this data :
{
'id': '1',
'object': [
{'code': 'a'},
{'code': 'b'},
{'code': 'c'}
]
}
And this query :
db.test.update({
'id': '1',
'object': {
'$elemMatch': {
'$or': [
{'code': 'b'},
{'code': 'c'}
]
}
}
},
{'$set':{'object.$.test':'ok'}}
)
Documents can contain one of these codes, both or none.
It works well with documents with one condition fulfilled.
In the case if there are 2 codes in the document, only the first one is updated :
I want to update both of them (code: 'b' AND code: 'c')
{
'id': '1',
'object': [
{'code': 'a', 'test': 'ok'},
{'code': 'b'}
]
}
This is what I want :
{
'id': '1',
'object': [
{'code': 'a', 'test': 'ok'},
{'code': 'b', 'test': 'ok'}
]
}
Thank you for helping.
$positional will update first matching element, for multiple elements update use arrayFilters.