How to delete document from MongoDB using Mongoengine? How to delete document from MongoDB using Mongoengine? mongodb mongodb

How to delete document from MongoDB using Mongoengine?


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

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

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

Food.objects(type="snacks").delete()


U can use the mongoshell and issue the following command:

db.collection.remove({your condition on documents you want to remove})

for example: From food collection you want to remove all the food which has type snacks. then you can issue the following command:

db.food.remove( { type : "snacks" } )