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 triggers in MongoDB?
- How to insert new document into MongoDB?
- How to use unwind in MongoDB?
- How to check the version of MongoDB?
- How to update an array element in MongoDB?
- How to list MongoDB users?
- What is MongoDB default port?
- How to join two collections in MongoDB?
- How to use MongoDB queue?
See more codes...