mongodbHow to delete many documents at once in MongoDB?
MongoDB provides a deleteMany() method to delete multiple documents from a collection. The syntax for deleteMany() is as follows:
db.collection.deleteMany(
<filter>,
{
justOne: <boolean>,
writeConcern: <document>
}
)
<filter>: Specifies the selection criteria to delete the documents.justOne: Optional. To delete only one document, set totrue. The default value isfalse, which deletes all documents that match the criteria.writeConcern: Optional. A document expressing the write concern.
For example, the following operation deletes all documents in the collection inventory where the status field equals A:
db.inventory.deleteMany( { status : "A" } )
The output of the above example will be:
{ "acknowledged" : true, "deletedCount" : 3 }
For more information, please refer to the MongoDB documentation.
More of Mongodb
- How to use watch in MongoDB?
- How to use unwind in MongoDB?
- How to rename a field in MongoDB?
- How to insert new document into MongoDB?
- How to remove a field from MongoDB?
- How to use triggers in MongoDB?
- How to do text search in MongoDB?
- How to use transactions in MongoDB?
- How to find by id in MongoDB?
- How to check the version of MongoDB?
See more codes...