The collection I have is like:
[{
"day": 10,
"orders": [{
"id": 1,
"items": {
"uuid1": {
"name": "item1",
"status": false
},
"uuid2": {
"name": "item2",
"status": true
},
"uuid3": {
"name": "item2",
"status": false
}
}
}]
},
{
"day": 11,
"orders": [{
"id": 1,
"items": {
"uuid1": {
"name": "item1",
"status": false
},
"uuid2": {
"name": "item2",
"status": true
},
"uuid3": {
"name": "item2",
"status": false
}
}
}]
}]
I would like to delete items with status marked as true for day 10. Tried the one below:
db.<collection>.update (
{day: 10},
{ $pull: {
orders: {items: { status: 'true'} } }
},
{multi: true}
);
The result is:
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
and so it doesn't delete.
How should we rewrite this update and pull query so that the items of day 10 marked with status as true are deleted?