diff options
Diffstat (limited to 'jstests/core/bulk_api_ordered.js')
-rw-r--r-- | jstests/core/bulk_api_ordered.js | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/jstests/core/bulk_api_ordered.js b/jstests/core/bulk_api_ordered.js index 87ecd66a1b5..a880cdb630e 100644 --- a/jstests/core/bulk_api_ordered.js +++ b/jstests/core/bulk_api_ordered.js @@ -20,32 +20,36 @@ var executeTests = function() { */ var bulkOp = coll.initializeOrderedBulkOp(); - assert.throws( function(){ bulkOp.find();} ); - assert.throws( function(){ bulkOp.insert({$key: 1});} ); + assert.throws(function() { + bulkOp.find(); + }); + assert.throws(function() { + bulkOp.insert({$key: 1}); + }); /** * Single successful ordered bulk operation */ var bulkOp = coll.initializeOrderedBulkOp(); - bulkOp.insert({a:1}); - bulkOp.find({a:1}).updateOne({$set: {b:1}}); + bulkOp.insert({a: 1}); + bulkOp.find({a: 1}).updateOne({$set: {b: 1}}); // no-op, should increment nMatched but not nModified - bulkOp.find({a:1}).updateOne({$set: {b:1}}); - bulkOp.find({a:2}).upsert().updateOne({$set: {b:2}}); - bulkOp.insert({a:3}); - bulkOp.find({a:3}).update({$set: {b:1}}); - bulkOp.find({a:3}).upsert().update({$set: {b:2}}); - bulkOp.find({a:10}).upsert().update({$set: {b:2}}); - bulkOp.find({a:2}).replaceOne({a:11}); - bulkOp.find({a:11}).removeOne(); - bulkOp.find({a:3}).remove({a:3}); + bulkOp.find({a: 1}).updateOne({$set: {b: 1}}); + bulkOp.find({a: 2}).upsert().updateOne({$set: {b: 2}}); + bulkOp.insert({a: 3}); + bulkOp.find({a: 3}).update({$set: {b: 1}}); + bulkOp.find({a: 3}).upsert().update({$set: {b: 2}}); + bulkOp.find({a: 10}).upsert().update({$set: {b: 2}}); + bulkOp.find({a: 2}).replaceOne({a: 11}); + bulkOp.find({a: 11}).removeOne(); + bulkOp.find({a: 3}).remove({a: 3}); var result = bulkOp.execute(); assert.eq(2, result.nInserted); assert.eq(2, result.nUpserted); assert.eq(5, result.nMatched); // only check nModified if write commands are enabled - if ( coll.getMongo().writeMode() == "commands" ) { - assert.eq(4, result.nModified); + if (coll.getMongo().writeMode() == "commands") { + assert.eq(4, result.nModified); } assert.eq(2, result.nRemoved); var upserts = result.getUpsertedIds(); @@ -58,29 +62,35 @@ var executeTests = function() { assert.eq(2, coll.find({}).itcount(), "find should return two documents"); // illegal to try to convert a multi-op batch into a SingleWriteResult - assert.throws(function() { result.toSingleResult(); } ); + assert.throws(function() { + result.toSingleResult(); + }); // attempt to re-run bulk operation - assert.throws(function() { bulkOp.execute(); } ); + assert.throws(function() { + bulkOp.execute(); + }); // Test SingleWriteResult var singleBatch = coll.initializeOrderedBulkOp(); - singleBatch.find({a:4}).upsert().updateOne({$set: {b:1}}); + singleBatch.find({a: 4}).upsert().updateOne({$set: {b: 1}}); var singleResult = singleBatch.execute().toSingleResult(); assert(singleResult.getUpsertedId() != null); // Create unique index coll.remove({}); - coll.ensureIndex({a : 1}, {unique : true}); + coll.ensureIndex({a: 1}, {unique: true}); /** * Single error ordered bulk operation */ var bulkOp = coll.initializeOrderedBulkOp(); - bulkOp.insert({b:1, a:1}); - bulkOp.find({b:2}).upsert().updateOne({$set: {a:1}}); - bulkOp.insert({b:3, a:2}); - var result = assert.throws( function() { bulkOp.execute(); } ); + bulkOp.insert({b: 1, a: 1}); + bulkOp.find({b: 2}).upsert().updateOne({$set: {a: 1}}); + bulkOp.insert({b: 3, a: 2}); + var result = assert.throws(function() { + bulkOp.execute(); + }); assert(result instanceof BulkWriteError); assert(result instanceof Error); // Basic properties check @@ -107,19 +117,21 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a : 1}, {unique : true}); + coll.ensureIndex({a: 1}, {unique: true}); /** * Multiple error ordered bulk operation */ var bulkOp = coll.initializeOrderedBulkOp(); - bulkOp.insert({b:1, a:1}); - bulkOp.find({b:2}).upsert().updateOne({$set: {a:1}}); - bulkOp.find({b:3}).upsert().updateOne({$set: {a:2}}); - bulkOp.find({b:2}).upsert().updateOne({$set: {a:1}}); - bulkOp.insert({b:4, a:3}); - bulkOp.insert({b:5, a:1}); - var result = assert.throws( function() { bulkOp.execute(); } ); + bulkOp.insert({b: 1, a: 1}); + bulkOp.find({b: 2}).upsert().updateOne({$set: {a: 1}}); + bulkOp.find({b: 3}).upsert().updateOne({$set: {a: 2}}); + bulkOp.find({b: 2}).upsert().updateOne({$set: {a: 1}}); + bulkOp.insert({b: 4, a: 3}); + bulkOp.insert({b: 5, a: 1}); + var result = assert.throws(function() { + bulkOp.execute(); + }); // Basic properties check assert.eq(1, result.nInserted); @@ -139,17 +151,17 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a : 1}, {unique : true}); + coll.ensureIndex({a: 1}, {unique: true}); }; -var buildVersion = parseInt(db.runCommand({buildInfo:1}).versionArray.slice(0, 3).join(""), 10); +var buildVersion = parseInt(db.runCommand({buildInfo: 1}).versionArray.slice(0, 3).join(""), 10); // Save the existing useWriteCommands function var _useWriteCommands = coll.getMongo().useWriteCommands; // // Only execute write command tests if we have > 2.5.5 otherwise // execute the down converted version -if(buildVersion >= 255) { +if (buildVersion >= 255) { // Force the use of useWriteCommands coll._mongo.useWriteCommands = function() { return true; |