bulkWrite()
Reference group: Collection CRUD methods
What it does
Runs mixed insert/update/replace/delete operations in one bulk request.
Syntax
db.collection.bulkWrite(operations, options)
Use case
Reduce round trips for batch maintenance.
Important notes
A bulk write is not automatically a multi-document transaction.
bulkWrite(): practical example
db.products.bulkWrite([{ updateOne: { filter: { sku: "KB-1" }, update: { $set: { active: false } } } }, { insertOne: { document: { sku: "KB-4" } } }])💡 Explanation
Runs mixed insert/update/replace/delete operations in one bulk request.
When to use it
Reduce round trips for batch maintenance.
Caution
A bulk write is not automatically a multi-document transaction.
Key Takeaways
- Runs mixed insert/update/replace/delete operations in one bulk request.
- Typical use: Reduce round trips for batch maintenance.