{
"partners" : [
{
"partnerId" : 5,
"topicIds" : [
"59de26f2e4b0f263704769e5"
]
},
{
"partnerId" : 45,
"topicIds" : [
"alpha",
"beta"
]
},
{
"partnerId" : 12345,
"topicIds" : [
"alpha"
]
}
]
}
I want to pull certain topicIds from specified partners. So for example I want to pull alpha topic from partnerId = 45 (the entry should remain with topicIds = ["beta"]).
I tried:
db.mypartnercoll.update({}, {$pull:{"partners":{"partnerId":45, "topicIds":{"$in":["alpha"]}}}})
however this removes the entire partnerId = 45 entry. I will have a single partnerId value and multiple topicIds to pull.
{$pull:{"partners.topicIds":{"partnerId":45, "topicIds":{"$in":["alpha"]}}}}WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 16837, "errmsg" : "cannot use the part (partners of partners.topicIds) to traverse the element ({partners: [ { partnerId: 5.0, topicIds: [ \"59de26f2e4b0f263704769e5\" ] }, { partnerId: 45.0, topicIds: [ \"alpha\", \"beta\" ] }, { partnerId: 12345.0, topicIds: [ \"alpha\" ] } ]})" } })