diff options
Diffstat (limited to 'src/mongo/shell/bulk_api.js')
-rw-r--r-- | src/mongo/shell/bulk_api.js | 160 |
1 files changed, 48 insertions, 112 deletions
diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js index 8ef10b5c976..2dfe15d65d2 100644 --- a/src/mongo/shell/bulk_api.js +++ b/src/mongo/shell/bulk_api.js @@ -22,14 +22,12 @@ var _bulk_api_module = (function() { * Helper function to define properties */ var defineReadOnlyProperty = function(self, name, value) { - Object.defineProperty(self, - name, - { - enumerable: true, - get: function() { - return value; - } - }); + Object.defineProperty(self, name, { + enumerable: true, + get: function() { + return value; + } + }); }; /** @@ -543,26 +541,24 @@ var _bulk_api_module = (function() { var batches = []; var defineBatchTypeCounter = function(self, name, type) { - Object.defineProperty(self, - name, - { - enumerable: true, - get: function() { - var counter = 0; - - for (var i = 0; i < batches.length; i++) { - if (batches[i].batchType == type) { - counter += batches[i].operations.length; - } - } - - if (currentBatch && currentBatch.batchType == type) { - counter += currentBatch.operations.length; - } - - return counter; - } - }); + Object.defineProperty(self, name, { + enumerable: true, + get: function() { + var counter = 0; + + for (var i = 0; i < batches.length; i++) { + if (batches[i].batchType == type) { + counter += batches[i].operations.length; + } + } + + if (currentBatch && currentBatch.batchType == type) { + counter += currentBatch.operations.length; + } + + return counter; + } + }); }; defineBatchTypeCounter(this, "nInsertOps", INSERT); @@ -634,9 +630,7 @@ var _bulk_api_module = (function() { var addIdIfNeeded = function(obj) { if (typeof(obj._id) == "undefined" && !Array.isArray(obj)) { var tmp = obj; // don't want to modify input - obj = { - _id: new ObjectId() - }; + obj = {_id: new ObjectId()}; for (var key in tmp) { obj[key] = tmp[key]; } @@ -667,12 +661,8 @@ var _bulk_api_module = (function() { // Set the top value for the update 0 = multi true, 1 = multi false var upsert = typeof currentOp.upsert == 'boolean' ? currentOp.upsert : false; // Establish the update command - var document = { - q: currentOp.selector, - u: updateDocument, - multi: true, - upsert: upsert - }; + var document = + {q: currentOp.selector, u: updateDocument, multi: true, upsert: upsert}; // Copy over the collation, if we have one. if (currentOp.hasOwnProperty('collation')) { @@ -691,12 +681,8 @@ var _bulk_api_module = (function() { // Set the top value for the update 0 = multi true, 1 = multi false var upsert = typeof currentOp.upsert == 'boolean' ? currentOp.upsert : false; // Establish the update command - var document = { - q: currentOp.selector, - u: updateDocument, - multi: false, - upsert: upsert - }; + var document = + {q: currentOp.selector, u: updateDocument, multi: false, upsert: upsert}; // Copy over the collation, if we have one. if (currentOp.hasOwnProperty('collation')) { @@ -723,10 +709,7 @@ var _bulk_api_module = (function() { collection._validateRemoveDoc(currentOp.selector); // Establish the removeOne command - var document = { - q: currentOp.selector, - limit: 1 - }; + var document = {q: currentOp.selector, limit: 1}; // Copy over the collation, if we have one. if (currentOp.hasOwnProperty('collation')) { @@ -743,10 +726,7 @@ var _bulk_api_module = (function() { collection._validateRemoveDoc(currentOp.selector); // Establish the remove command - var document = { - q: currentOp.selector, - limit: 0 - }; + var document = {q: currentOp.selector, limit: 0}; // Copy over the collation, if we have one. if (currentOp.hasOwnProperty('collation')) { @@ -781,9 +761,7 @@ var _bulk_api_module = (function() { if (selector == undefined) throw Error("find() requires query criteria"); // Save a current selector - currentOp = { - selector: selector - }; + currentOp = {selector: selector}; // Return the find Operations return findOperations; @@ -857,11 +835,7 @@ var _bulk_api_module = (function() { // Generate the right update if (batch.batchType == UPDATE) { - cmd = { - update: coll.getName(), - updates: batch.operations, - ordered: ordered - }; + cmd = {update: coll.getName(), updates: batch.operations, ordered: ordered}; } else if (batch.batchType == INSERT) { var transformedInserts = []; batch.operations.forEach(function(insertDoc) { @@ -869,17 +843,9 @@ var _bulk_api_module = (function() { }); batch.operations = transformedInserts; - cmd = { - insert: coll.getName(), - documents: batch.operations, - ordered: ordered - }; + cmd = {insert: coll.getName(), documents: batch.operations, ordered: ordered}; } else if (batch.batchType == REMOVE) { - cmd = { - delete: coll.getName(), - deletes: batch.operations, - ordered: ordered - }; + cmd = {delete: coll.getName(), deletes: batch.operations, ordered: ordered}; } // If we have a write concern @@ -910,7 +876,8 @@ var _bulk_api_module = (function() { -1 /* limit */, 0 /* skip */, 0 /* batchSize */, - 0 /* flags */).next(); + 0 /* flags */) + .next(); if (result.ok == 0) { throw new WriteCommandError(result); @@ -971,17 +938,11 @@ var _bulk_api_module = (function() { var code = gleResponse.code; var timeout = gleResponse.wtimeout ? true : false; - var extractedErr = { - writeError: null, - wcError: null, - unknownError: null - }; + var extractedErr = {writeError: null, wcError: null, unknownError: null}; if (err == 'norepl' || err == 'noreplset') { // Know this is legacy gle and the repl not enforced - write concern error in 2.4. - var errObj = { - code: WRITE_CONCERN_FAILED - }; + var errObj = {code: WRITE_CONCERN_FAILED}; if (errMsg != '') { errObj.errmsg = errMsg; @@ -994,9 +955,7 @@ var _bulk_api_module = (function() { extractedErr.wcError = errObj; } else if (timeout) { // Know there was not write error. - var errObj = { - code: WRITE_CONCERN_FAILED - }; + var errObj = {code: WRITE_CONCERN_FAILED}; if (errMsg != '') { errObj.errmsg = errMsg; @@ -1004,35 +963,21 @@ var _bulk_api_module = (function() { errObj.errmsg = err; } - errObj.errInfo = { - wtimeout: true - }; + errObj.errInfo = {wtimeout: true}; extractedErr.wcError = errObj; } else if (code == 19900 || // No longer primary code == 16805 || // replicatedToNum no longer primary code == 14330 || // gle wmode changed; invalid code == NOT_MASTER || code == UNKNOWN_REPL_WRITE_CONCERN || code == WRITE_CONCERN_FAILED) { - extractedErr.wcError = { - code: code, - errmsg: errMsg - }; + extractedErr.wcError = {code: code, errmsg: errMsg}; } else if (!isOK) { // This is a GLE failure we don't understand - extractedErr.unknownError = { - code: code, - errmsg: errMsg - }; + extractedErr.unknownError = {code: code, errmsg: errMsg}; } else if (err != '') { - extractedErr.writeError = { - code: (code == 0) ? UNKNOWN_ERROR : code, - errmsg: err - }; + extractedErr.writeError = {code: (code == 0) ? UNKNOWN_ERROR : code, errmsg: err}; } else if (jNote != '') { - extractedErr.writeError = { - code: WRITE_CONCERN_FAILED, - errmsg: jNote - }; + extractedErr.writeError = {code: WRITE_CONCERN_FAILED, errmsg: jNote}; } // Handling of writeback not needed for mongo shell. @@ -1043,9 +988,7 @@ var _bulk_api_module = (function() { * getLastErrorMethod that supports all write concerns */ var executeGetLastError = function(db, options) { - var cmd = { - getlasterror: 1 - }; + var cmd = {getlasterror: 1}; cmd = Object.extend(cmd, options); // Execute the getLastErrorCommand return db.runCommand(cmd); @@ -1054,11 +997,7 @@ var _bulk_api_module = (function() { // Execute the operations, serially var executeBatchWithLegacyOps = function(batch) { - var batchResult = { - n: 0, - writeErrors: [], - upserted: [] - }; + var batchResult = {n: 0, writeErrors: [], upserted: []}; var extractedErr = null; @@ -1234,10 +1173,7 @@ var _bulk_api_module = (function() { var explainBatch = batches[0]; var writeCmd = buildBatchCmd(explainBatch); - return { - "explain": writeCmd, - "verbosity": verbosity - }; + return {"explain": writeCmd, "verbosity": verbosity}; }; }; |