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 work with time series data in MongoDB?
- How to check the version of MongoDB?
- How to bind IP addresses for MongoDB server?
- How to use watch in MongoDB?
- How to use MongoDB pull?
- How to empty an array in MongoDB?
- What is MongoDB default port?
- How to query with "not equal" condition in MongoDB?
- How to use findone in MongoDB?
- How to install MongoDB on Mac?
See more codes...