I have a collection in MongoDB. And want to remove an item from array.
My "users" collection is an array of objects.
When I type:
db.users.find({"tasks.task_id" : "h58sjIdj3jJZ"}).pretty()
in mongo shell, I get this result:
{
"_id" : ObjectId("5955b45b7a4bf40544019359"),
"profile" : {
"name" : "Morning bay",
"email" : "[email protected]",
"phone" : "+1-641-155-88-84",
"description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
},
"tasks" : [
{
"task_id" : "h58sjIdj3jJY",
"time" : "11:15 AM",
"date" : "07/01/2017",
"description" : "Make 1st call to John White"
},
{
"task_id" : "h58sjIdj3jJZ",
"time" : "14:30 PM",
"date" : "07/09/2017",
"description" : "Send certificate and make Another call to J.White"
}
],
"progress" : [
{
"isActive" : "",
"description" : ""
}
]
}
So, every item in my collection looks like this. And it's ok.
But now I want to remove one item from "tasks" array in one of users items.
I type:
db.users.update({}, {$pull : {"tasks" : {"task_id" : "h58sjIdj3jJZ"}}});
an get this result:
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
I read documentation and examples in it look similar, so I don't understand where is an error.
db.users.update({}, {$pull : {"tasks" : {"task_id" : "h58sjIdj3jJZ"}}}, { multi:true } );