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.