Currently I have a data structure like this in mongo:
{
"_id": "field00048",
"colorValues": [
{
"stateField": "Open1",
"color": "purple"
},
{
"stateField": "Open2",
"color": "blue"
}
]
}
I am using the mongo shell to create a query using $pullAll to delete both of the objects in the colorValues array by matching on the stateField field. I have tried these queries but none of them actually delete the records they match on.
db.admin.fields.update({_id: "field00048"}, {$pullAll: {stateField: ["Open1", "Open2"]}});
and
db.admin.fields.update({_id: "field00048"}, {$pullAll: {colorValues: ["Open1", "Open2"]}});
and
db.admin.fields.update({_id: "field00048"}, {$pullAll: {colorValues: [{stateField:"Open1"}, {stateField:"Open2"}]}});
and
db.admin.fields.update({_id: "field00048"}, {$pullAll: {colorValues.stateField: ["Open1", "Open2"]}});
and
db.admin.fields.update({_id: "field00048"}, {$pullAll: {colorValues: stateField:{["Open1", "Open2"]}}});
Any suggestions?
Thanks!
The query that solved this was:
db.admin.fields.update({_id: "field00048"}, {$pull: {colorValues:{stateField:{$in: ["Open1", "Open2"]}}}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With