pull from mongo nested array

Question
{
    "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.


Show source
| arrays   | database   | mongodb   | aggregate   2017-11-06 16:11 0 Answers

Answers to pull from mongo nested array ( 0 )

Leave a reply to - pull from mongo nested array

◀ Go back