Class OrderedBulkOperation

Hierarchy

Properties

isOrdered: boolean
operationId?: number

Accessors

Methods

  • Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne. Returns a builder object used to complete the definition of the operation.

    Parameters

    Returns FindOperators

    Example

    const bulkOp = collection.initializeOrderedBulkOp();

    // Add an updateOne to the bulkOp
    bulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });

    // Add an updateMany to the bulkOp
    bulkOp.find({ c: 3 }).update({ $set: { d: 4 } });

    // Add an upsert
    bulkOp.find({ e: 5 }).upsert().updateOne({ $set: { f: 6 } });

    // Add a deletion
    bulkOp.find({ g: 7 }).deleteOne();

    // Add a multi deletion
    bulkOp.find({ h: 8 }).delete();

    // Add a replaceOne
    bulkOp.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 executed
    await bulkOp.execute();

Generated using TypeDoc