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 -
find(selector){UnorderedBulkOperation}
-
Initiate a find operation for an update/updateOne/remove/removeOne/replaceOne
Name Type Description selector
object The selector for the bulk operation.
Throws:
MongoError -
insert(doc){UnorderedBulkOperation}
-
Add a single insert document to the bulk operation
Name Type Description doc
object the document to insert
Throws:
MongoError -
remove(){UnorderedBulkOperation}
-
Add a remove operation to the bulk operation
Throws:
MongoError -
removeOne(){UnorderedBulkOperation}
-
Add a remove one operation to the bulk operation
Throws:
MongoError -
replaceOne(doc){UnorderedBulkOperation}
-
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 -
update(doc){UnorderedBulkOperation}
-
Add a single update document to the bulk operation
Name Type Description doc
object update operations
Throws:
MongoErrorExample
// 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(); }); });
-
updateOne(doc){UnorderedBulkOperation}
-
Add a single update one document to the bulk operation
Name Type Description doc
object update operations
Throws:
MongoError -
upsert(){UnorderedBulkOperation}
-
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.