I have a collection of scam phone numbers containing comments from different users. Each user has a unique display name. I am trying to delete all comments specific to that user name. So far I can find the documents containing comments from that specific username using:
db.collection.find({"comments":{$elemMatch:{creator:"name"}}})
I want to delete only the user's comments of all posts, not the posting itself. I feel like I'm close but can't find a
Find results:
{ "_id" : ObjectId("5b84a319ec18e50d9093f3aa"),
"phoneNumber" : 2334445555,
"flags" : 1,
"description" : "Charity",
"comments" : [
{ "_id" : ObjectId("5b84a319ec18e50d9093f3ab"), "content" : "Red cross asked me to donate using Moneygram", "creator" : "jv3123", "created" : ISODate("2018-08-28T01:19:21.368Z") } ], "created" : ISODate("2018-08-28T01:19:21.369Z"), "__v" : 0 }
{ "_id" : ObjectId("5b84a4e2ec18e50d9093f3ac"),
"phoneNumber" : 2334445555,
"flags" : 1,
"description" : "Charity",
"comments" : [
{ "_id" : ObjectId("5b84a4e2ec18e50d9093f3ad"), "content" : "Red cross rep asked me to send money through Moneygram", "creator" : "jv3123", "created" : ISODate("2018-08-28T01:26:58.532Z") } ], "db.phoneNumberData.find({"comments":{$elemMatch:{creator:"jv3123"}}})
{ "_id" : ObjectId("5b84a319ec18e50d9093f3aa"),
"phoneNumber" : 2334445555,
"flags" : 1,
"description" : "Charity",
"comments" : [ { "_id" : ObjectId("5b84a319ec18e50d9093f3ab"), "content" : "Red cross asked me to donate using Moneygram", "creator" : "jv3123", "created" : ISODate("2018-08-28T01:19:21.368Z") } ], "created" : ISODate("2018-08-28T01:19:21.369Z"), "__v" : 0 }
{ "_id" : ObjectId("5b84a4e2ec18e50d9093f3ac"),
"phoneNumber" : 2334445555, "flags" : 1, "description" : "Charity", "comments" : [ { "_id" : ObjectId("5b84a4e2ec18e50d9093f3ad"), "content" : "Red cross rep asked me to send money through Moneygram", "creator" : "jv3123", "created" : ISODate("2018-08-28T01:26:58.532Z") } ], "created" : ISODate("2018-08-28T01:26:58.532Z"), "__v" : 0 }