How to delete a specific document from a collection in MongoDB?

0
The remove () method used in this way: db.collection.remove () removes all documents from a collection, how do I remove a specific document?

    
asked by anonymous 10.10.2016 / 08:50

1 answer

1

If you want to remove by the id you can use the following query:

db.collection.remove({"_id": ObjectId("5798ffcd60b2d8a4066b482d")});

You can remove using the same structure as a find. For example, you can remove all records that are larger than 10.

db.collection.remove({quantidade : {$gt :10}})
    
10.10.2016 / 14:33