'How to delete the element from document in Mongodb?
I have this collection in MongoDB and I want to delete "Bangalore" as shown below.
{
"_id": "1",
"UserName": "Mike",
"UserDetails": [{
"UserCountryName": "India",
"UserLocation": [
"Bangalore",
"Chennai",
"Delhi",
"Mumbai"
]
}]
}
I tried the below query but it didn't work. The whole UserDetails array is getting deleted. I want only "Banglore" to be deleted. Please help.
db.user.update(
{ },
{ $pull: { "UserDetails": {"UserLocation":"Bangalore"} } }
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
