Class BulkOperationBaseAbstract

Hierarchy

Properties

isOrdered: boolean
operationId?: number

Accessors

Methods

  • Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.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将updateOne添加到bulkOp
    bulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });

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

    // Add an upsert添加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添加replaceOne
    bulkOp.find({ i: 9 }).replaceOne({writeConcern: { j: 10 }});

    // Update using a pipeline (requires Mongodb 4.2 or higher)使用管道更新(需要Mongodb 4.2或更高版本)
    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();
  • Add a single insert document to the bulk operation将单个插入文档添加到批量操作

    Parameters

    Returns BulkOperationBase

    Example

    const bulkOp = collection.initializeOrderedBulkOp();

    // Adds three inserts to the bulkOp.向bulkOp添加三个插入项。
    bulkOp
    .insert({ a: 1 })
    .insert({ b: 2 })
    .insert({ c: 3 });
    await bulkOp.execute();

Generated using TypeDoc