Reputation: 619
i have the following document in my collection:
"_id" : "12345",
"name" : "test",
"users" : [
{
"name" : "spiderman",
"email" : "[email protected]",
"accepted" : true
},
{
"name" : "superman",
"email" : "[email protected]",
"accepted" : true
}
]
I would like to remove the user superman.
This is what i would like my final result to look like:
"_id" : "12345",
"name" : "test",
"users" : [
{
"name" : "spiderman",
"email" : "[email protected]",
"accepted" : true
}
]
Ive tried a few things but nothing worked so far. Any help is appreciated.
Thank you
Upvotes: 0
Views: 67
Reputation: 104775
You can use $pull
db.collection.update(
{ "users.name": "superman" },
{ $pull: { "users": {"name" : "superman"} } },
{ multi: false}
)
Upvotes: 1