‘db.collectionName.deleteMany({})’ statement delete all the documents from a collection.
Example
db.employee.deleteMany({})
> db.employee.find()
{ "_id" : ObjectId("60ba0a678e67ad0ff5b02998"), "firstName" : "Jessi" }
{ "_id" : ObjectId("60ba0b278e67ad0ff5b02999"), "id" : 34, "name" : "Anand", "age" : 42, "designation" : "Manager" }
{ "_id" : ObjectId("60baeb13baf44d88348459be"), "name" : "Krishna" }
>
> db.employee.deleteMany({})
{ "acknowledged" : true, "deletedCount" : 3 }
>
> db.employee.find()
>
No comments:
Post a Comment