Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne. Returns a builder object used to complete the definition of the operation.
const bulkOp = collection.initializeOrderedBulkOp();// Add an updateOne to the bulkOpbulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });// Add an updateMany to the bulkOpbulkOp.find({ c: 3 }).update({ $set: { d: 4 } });// Add an upsertbulkOp.find({ e: 5 }).upsert().updateOne({ $set: { f: 6 } });// Add a deletionbulkOp.find({ g: 7 }).deleteOne();// Add a multi deletionbulkOp.find({ h: 8 }).delete();// Add a replaceOnebulkOp.find({ i: 9 }).replaceOne({writeConcern: { j: 10 }});// Update using a pipeline (requires Mongodb 4.2 or higher)bulk.find({ k: 11, y: { $exists: true }, z: { $exists: true } }).updateOne([ { $set: { total: { $sum: [ '$y', '$z' ] } } }]);// All of the ops will now be executedawait bulkOp.execute();
Add a single insert document to the bulk operation
const bulkOp = collection.initializeOrderedBulkOp();// Adds three inserts to the bulkOp.bulkOp .insert({ a: 1 }) .insert({ b: 2 }) .insert({ c: 3 });await bulkOp.execute();
Specifies a raw operation to perform in the bulk write.
Generated using TypeDoc
Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne. Returns a builder object used to complete the definition of the operation.