summaryrefslogtreecommitdiff
path: root/src/mongo/shell/bulk_api.js
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2014-02-18 14:24:53 -0500
committerMatt Kangas <matt.kangas@mongodb.com>2014-02-18 16:18:02 -0500
commitf85398cf07b9bf082d09689389234f9bc06cc6a3 (patch)
tree2c5f37c5d4ec3d5a411ace2e48de7934ee6d1876 /src/mongo/shell/bulk_api.js
parent617b4896241649e2a3203e33e5901907790002b5 (diff)
downloadmongo-f85398cf07b9bf082d09689389234f9bc06cc6a3.tar.gz
Bulk find() requires selector, SERVER-12553.
Squashed: - Update comments in bulk_api.js. - Throw Error from invalid Bulk operations, not strings Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'src/mongo/shell/bulk_api.js')
-rw-r--r--src/mongo/shell/bulk_api.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js
index a3d5ac66be0..1d87404b7ad 100644
--- a/src/mongo/shell/bulk_api.js
+++ b/src/mongo/shell/bulk_api.js
@@ -2,7 +2,7 @@
// Scope for the function
//
var _bulk_api_module = (function() {
- // Insert types
+ // Batch types
var NONE = 0;
var INSERT = 1;
var UPDATE = 2;
@@ -242,7 +242,8 @@ var _bulk_api_module = (function() {
* @return {SingleWriteResult} the simplified results condensed into one.
*/
this.toSingleResult = function() {
- if(singleBatch == null) throw "Cannot output SingleWriteResult from multiple batch result";
+ if(singleBatch == null) throw Error(
+ "Cannot output SingleWriteResult from multiple batch result");
return new SingleWriteResult(bulkResult, singleBatch);
}
};
@@ -308,7 +309,7 @@ var _bulk_api_module = (function() {
}
/**
- * Keeps the state of a unordered batch so we can rewrite the results
+ * Keeps the state of an unordered batch so we can rewrite the results
* correctly after command execution
*/
var Batch = function(batchType, originalZeroIndex) {
@@ -318,7 +319,7 @@ var _bulk_api_module = (function() {
}
/**
- * Wraps a legacy operation so we can correctly rewrite it's error
+ * Wraps a legacy operation so we can correctly rewrite its error
*/
var LegacyOp = function(batchType, operation, index) {
this.batchType = batchType;
@@ -441,7 +442,7 @@ var _bulk_api_module = (function() {
// We have an array of documents
if(Array.isArray(document)) {
- throw new "operation passed in cannot be an Array";
+ throw Error("operation passed in cannot be an Array");
} else {
currentBatch.operations.push(document)
currentIndex = currentIndex + 1;
@@ -531,7 +532,7 @@ var _bulk_api_module = (function() {
removeOne: function() {
collection._validateRemoveDoc(currentOp.selector);
- // Establish the update command
+ // Establish the removeOne command
var document = {
q: currentOp.selector
, limit: 1
@@ -546,7 +547,7 @@ var _bulk_api_module = (function() {
remove: function() {
collection._validateRemoveDoc(currentOp.selector);
- // Establish the update command
+ // Establish the remove command
var document = {
q: currentOp.selector
, limit: 0
@@ -562,6 +563,7 @@ var _bulk_api_module = (function() {
//
// Start of update and remove operations
this.find = function(selector) {
+ if (selector == undefined) throw Error("find() requires query criteria");
// Save a current selector
currentOp = {
selector: selector
@@ -581,7 +583,9 @@ var _bulk_api_module = (function() {
//
if(ordered && result && result.writeConcernError
&& (result.writeConcernError.code == 2 || result.writeConcernError.code == 75)) {
- throw "legacy batch failed, cannot aggregate results: " + result.writeConcernError.errmsg;
+ throw Error(
+ "legacy batch failed, cannot aggregate results: "
+ + result.writeConcernError.errmsg);
}
// If we have an insert Batch type
@@ -589,7 +593,7 @@ var _bulk_api_module = (function() {
bulkResult.nInserted = bulkResult.nInserted + result.n;
}
- // If we have an insert Batch type
+ // If we have a remove batch type
if(batch.batchType == REMOVE) {
bulkResult.nRemoved = bulkResult.nRemoved + result.n;
}
@@ -681,7 +685,8 @@ var _bulk_api_module = (function() {
0 /* flags */).next();
if(result.ok == 0) {
- throw "batch failed, cannot aggregate results: " + result.errmsg;
+ throw Error(
+ "batch failed, cannot aggregate results: " + result.errmsg);
}
// Merge the results
@@ -881,7 +886,7 @@ var _bulk_api_module = (function() {
//
// Execute the batch
this.execute = function(_writeConcern) {
- if(executed) throw "operations cannot be re-executed";
+ if(executed) throw Error("operations cannot be re-executed");
// If writeConcern set, use it, else get from collection (which will inherit from db/mongo)
writeConcern = _writeConcern ? _writeConcern : coll.getWriteConcern();