Class: UnorderedBulkOperation

UnorderedBulkOperation

new UnorderedBulkOperation(){UnorderedBulkOperation}

Create a new UnorderedBulkOperation instance (INTERNAL TYPE, do not instantiate directly)

Returns:
UnorderedBulkOperation instance.

Methods

execute(options, callback){null}

Execute the ordered bulk operation

Name Type Default Description
options object null optional

Optional settings.

Name Type Default Description
w number | string null optional

The write concern.

wtimeout number null optional

The write concern timeout.

j boolean false optional

Specify a journal write concern.

fsync boolean false optional

Specify a file sync write concern.

callback UnorderedBulkOperation~resultCallback

The result callback

Throws:
MongoError

Initiate a find operation for an update/updateOne/remove/removeOne/replaceOne

Name Type Description
selector object

The selector for the bulk operation.

Throws:
MongoError

Add a single insert document to the bulk operation

Name Type Description
doc object

the document to insert

Throws:
MongoError

Add a remove operation to the bulk operation

Throws:
MongoError

Add a remove one operation to the bulk operation

Throws:
MongoError

Add a replace one operation to the bulk operation

Name Type Description
doc object

the new document to replace the existing one with

Throws:
MongoError

Add a single update document to the bulk operation

Name Type Description
doc object

update operations

Throws:
MongoError
Example
// Example of a simple ordered insert/update/upsert/remove ordered collection

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('batch_write_unordered_ops_legacy_0');
  // Initialize the unordered Batch
  var batch = col.initializeUnorderedBulkOp({useLegacyOps: true});

  // Add some operations to be executed in order
  batch.insert({a:1});
  batch.find({a:1}).updateOne({$set: {b:1}});
  batch.find({a:2}).upsert().updateOne({$set: {b:2}});
  batch.insert({a:3});
  batch.find({a:3}).remove({a:3});

  // Execute the operations
  batch.execute(function(err, result) {
    // Check state of result
    test.equal(2, result.nInserted);
    test.equal(1, result.nUpserted);
    test.equal(1, result.nMatched);
    test.ok(1 == result.nModified || result.nModified == null);
    test.equal(1, result.nRemoved);

    var upserts = result.getUpsertedIds();
    test.equal(1, upserts.length);
    test.equal(2, upserts[0].index);
    test.ok(upserts[0]._id != null);
    
    var upsert = result.getUpsertedIdAt(0);
    test.equal(2, upsert.index);
    test.ok(upsert._id != null);

    // Finish up test
    db.close();
  });
});

Add a single update one document to the bulk operation

Name Type Description
doc object

update operations

Throws:
MongoError

Upsert modifier for update bulk operation

Throws:
MongoError

Type Definitions

resultCallback(error, result)

The callback format for results

Name Type Description
error MongoError

An error instance representing the error during the execution.

result BulkWriteResult

The bulk write result.

comments powered by Disqus
Documentation generated by JSDoc 3.3.0-alpha9 on Wed Oct 29 2014 13:10:24 GMT+0100 (CET)