I have this data in Mongo:
{
"_id": ObjectId("505fd43fdbed3dd93f0ae088"),
"categoryName": "Cat 1",
"services": [
{
"serviceName": "Svc 1",
"input": [
-------------------------------------------------------------------------
{ "quantity": 10, "note": "quantity = 10" },
-------------------------------------------------------------------------
{ "quantity": 20, "note": "quantity = 20" }
]
},
{
"serviceName": "Svc 2",
"input": [
{ "quantity": 30, "note": "quantity = 30" },
{ "quantity": 40, "note": "quantity = 40" }
]
}
]
}
Now I want to pull element { "quantity" : 10, "note" : "quantity = 10" } of input array. How can I do with Mongo?
You would use the
$pulloperator with anupdateto do that, using the$positional operator to identify whichserviceselement you’re targeting: