In MongoDB, I have documents defined like:
{
'foo': {
'a': [1,2,3,4,5],
'b': [1,5,9],
'c': [2,5,7]
}
}
I’m looking for a simple way to remove, for instance, the number 2 in each list where it appears. In this example, that would update this document to:
{
'foo': {
'a': [1,3,4,5],
'b': [1,5,9],
'c': [5,7]
}
}
Is there any solution for this?
Thanks.
You can’t do it using atomic updates, because of positional operator will update only first matched item in nested array. You can make multiple update only for root level fields.
There is only one solution: load document, update nested array and save.