i have the following records in the collection ilists
db.ilists.find()
{ "_id" : ObjectId("5efb10f25372d01d549954b1"), "name" : "hello user", "__v" : 0 }
{ "_id" : ObjectId("5efb10f25372d01d549954b2"), "name" : "click + to add items to the list", "__v" : 0 }
{ "_id" : ObjectId("5efb10f25372d01d549954b3"), "name" : "<---click the checkbox to deletet item in the list", "__v" : 0 }
{ "_id" : ObjectId("5efb170a32b1290c64950999"), "__v" : 0 }
{ "_id" : ObjectId("5efb17790d9ff700204c43c2"), "__v" : 0 }
i have two empty documents and i am using deleteMany to delete them but i am getting the following
> db.ilists.deleteMany({"_id":"5efb170a32b1290c64950999"},{"_id":"5efb17790d9ff700204c43c2"})
{ "acknowledged" : true, "deletedCount" : 0 }
as you can see the deleted count is 0 and those documents are not being deleted any help for this?
According to the documentation , deleteMany
expects filter query as the first argument. In your case, since the first argument does seem like a query, it's not working as expected.
You may try using the following:
db.ilists.remove( { _id : { $in: [
ObjectId("5efb170a32b1290c64950999"),
ObjectId("5efb17790d9ff700204c43c2"),
] } } );
Alternatively, if you plan to delete all the empty documents, you can update your deleteMany
query as below:
db.ilists.deleteMany({ name: {$exists: false} })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.