Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete document from MongoDB using Mongoengine?

How to delete document from MongoDB using Mongoengine? I'veread the API reference here:
http://docs.mongoengine.org/apireference.html
but I can not understand what is:

delete(**write_concern) 

Do you have any idea?

like image 742
ehsan shirzadi Avatar asked Jul 31 '14 09:07

ehsan shirzadi


People also ask

How do I delete MongoEngine?

You can either delete an single Document instance by calling its delete method: lunch = Food. objects. first() // Get a single 'Food' instance lunch.

What is the command used to delete records in MongoDB?

By default, remove() removes all documents that match the query expression. Specify the justOne option to limit the operation to removing a single document. To delete a single document sorted by a specified order, use the findAndModify() method.

How do I remove all files from a collection in MongoDB?

To delete all documents in a collection, pass an empty document ({}). To limit the deletion to just one document, set to true. Omit to use the default value of false and delete all documents matching the deletion criteria.


1 Answers

You can either delete an single Document instance by calling its delete method:

lunch = Food.objects.first() // Get a single 'Food' instance lunch.delete() // Delete it! 

Or you can delete all items matching a query like so:

Food.objects(type="snacks").delete() 
like image 197
Ross Avatar answered Sep 29 '22 17:09

Ross