summaryrefslogtreecommitdiff
path: root/src/mongo/shell/bulk_api.js
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-03-14 11:59:18 -0400
committerGreg Studer <greg@10gen.com>2014-03-17 10:02:22 -0400
commitb5756056a7b5acba550a7d31a587f3a5b7651e00 (patch)
treec74127db66b4845b2a9ff44b468551dadfeb75f6 /src/mongo/shell/bulk_api.js
parentecc00b5bfba8961e0884e591ba1866eeb0cb67ab (diff)
downloadmongo-b5756056a7b5acba550a7d31a587f3a5b7651e00.tar.gz
SERVER-12977 disallow empty write batches
Also fix shell batch processing to avoid extra empty batches.
Diffstat (limited to 'src/mongo/shell/bulk_api.js')
-rw-r--r--src/mongo/shell/bulk_api.js36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js
index 5af814b81d9..2dd2bb94ff2 100644
--- a/src/mongo/shell/bulk_api.js
+++ b/src/mongo/shell/bulk_api.js
@@ -431,34 +431,30 @@ var _bulk_api_module = (function() {
// Add to internal list of documents
var addToOperationsList = function(docType, document) {
+
+ if (Array.isArray(document))
+ throw Error("operation passed in cannot be an Array");
+
// Get the bsonSize
var bsonSize = Object.bsonsize(document);
+
// Create a new batch object if we don't have a current one
if(currentBatch == null) currentBatch = new Batch(docType, currentIndex);
+ // Finalize and create a new batch if this op would take us over the
+ // limits *or* if this op is of a different type
+ if(currentBatchSize + 1 > maxNumberOfDocsInBatch
+ || (currentBatchSize > 0 &&
+ currentBatchSizeBytes + bsonSize >= maxBatchSizeBytes)
+ || currentBatch.batchType != docType) {
+ finalizeBatch(docType);
+ }
+
+ currentBatch.operations.push(document);
+ currentIndex = currentIndex + 1;
// Update current batch size
currentBatchSize = currentBatchSize + 1;
currentBatchSizeBytes = currentBatchSizeBytes + bsonSize;
-
- // Finalize and create a new batch if we have a new operation type
- if (currentBatch.batchType != docType) {
- finalizeBatch(docType);
- }
-
- // We have an array of documents
- if(Array.isArray(document)) {
- throw Error("operation passed in cannot be an Array");
- } else {
- currentBatch.operations.push(document)
- currentIndex = currentIndex + 1;
- }
-
- // Check if the batch exceeds one of the size limits
- if((currentBatchSize >= maxNumberOfDocsInBatch)
- || (currentBatchSizeBytes >= maxBatchSizeBytes)) {
- finalizeBatch(docType);
- }
-
};
/**