Skip to content

Commit

Permalink
fix(bulkWrite): always count undefined values in bson size for bulk
Browse files Browse the repository at this point in the history
Bulk Writes use bson.calculateObjectSize to determine the size of
batches. However, it was not respecting user or default option
values like ignoreUndefined, which lead to bulkWrite errors in
some edge cases. To be safe, it now always sets ignoreUndefined to
false.

Fixes NODE-1898
  • Loading branch information
daprahamian committed Mar 18, 2019
1 parent 73ef728 commit 436d340
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/bulk/ordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const isPromiseLike = require('../utils').isPromiseLike;
function addToOperationsList(bulkOperation, docType, document) {
// Get the bsonSize
const bsonSize = bson.calculateObjectSize(document, {
checkKeys: false
checkKeys: false,

// Since we don't know what the user selected for BSON options here,
// err on the safe side, and check the size with ignoreUndefined: false.
ignoreUndefined: false
});

// Throw error if the doc is bigger than the max BSON size
Expand Down
6 changes: 5 additions & 1 deletion lib/bulk/unordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const isPromiseLike = require('../utils').isPromiseLike;
function addToOperationsList(bulkOperation, docType, document) {
// Get the bsonSize
const bsonSize = bson.calculateObjectSize(document, {
checkKeys: false
checkKeys: false,

// Since we don't know what the user selected for BSON options here,
// err on the safe side, and check the size with ignoreUndefined: false.
ignoreUndefined: false
});
// Throw error if the doc is bigger than the max BSON size
if (bsonSize >= bulkOperation.s.maxBatchSizeBytes)
Expand Down

0 comments on commit 436d340

Please sign in to comment.