1

I have the following mongo structure:

{
"_id": 123,
"rooms": [
    {
        "room_code": 456,
        "img": [
            {
                "link": "blah",
                "title": "Title"
            },
            {
                "link": "blah2",
                "title": "Title2"
            }
        ]
    },
    {
        "room_code": 789,
        "img": [
            {
                "link": "blah",
                "title": "Title"
            },
            {
                "link": "blah3",
                "title": "Title3"
            }
        ]
    }
]
}

Now, I want to remove those elements from "rooms.img" key where "link":"blah". Like this:

{
"_id": 123,
"rooms": [
    {
        "room_code": 456,
        "img": [
            {
                "link": "blah2",
                "title": "Title2"
            }
        ]
    },
    {
        "room_code": 789,
        "img": [
            {
                "link": "blah3",
                "title": "Title3"
            }
        ]
    }
]
}

I tried using,

db.collections.update({"_id":123},{$pull: { 'rooms':{'img': { 'l': 'blah' } }}})

db.collections.update({"_id":123},{$pull: { 'room_info.img': { 'l': 'blah' } }})

But neither of them is working. How to remove an element from a list("img") which is part of another list ("rooms")? Please advise.

Sudipta
  • 4,773
  • 2
  • 27
  • 42

1 Answers1

0

You should use the projection opperator Doc

In addition look at my old post : Here

Community
  • 1
  • 1
Lombric
  • 830
  • 2
  • 11
  • 23