The database I have is a list of contacts with a structure like this
{
"_id" : ObjectId("5bb4fff62dba3129388423fa"),
"user_id" : 1,
"custom_list_id" : "VDFLVPMK",
"list_name" : "New Test List",
"contacts" : [
{
"email" : "test1@gmail.com",
"first_name" : "Jane",
"last_name" : "Doe",
"address" : "",
"subscribed" : true,
"date_added" : ISODate("2018-10-03T17:44:30.975Z"),
"date_changed" : ISODate("2018-10-03T17:44:30.975Z")
},
{
"email" : "test@gmail.com",
"first_name" : "John",
"last_name" : "Doe",
"address" : "",
"subscribed" : true,
"date_added" : ISODate("2018-10-03T17:49:58.795Z"),
"date_changed" : ISODate("2018-10-03T17:49:58.795Z")
}
]
}
I am trying to remove one person in the contacts without removing everything in the list. I am trying to run the command in the MongoDB terminal and it is not doing anything
Command
db.customer__list__info.update({contacts:[]},{$pull:{'contacts.email':'test1@gmail.com'}})
Result
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
What I would like is for it to get rid of everything inside the { }
with the specified email.
Any help would be much appreciated.