From e806be49e83a3b20b5e688fc0ff1238bc7bb235f Mon Sep 17 00:00:00 2001 From: Amotz Terem Date: Wed, 23 Jan 2019 00:07:02 +0200 Subject: [PATCH] fix(bulk): honor ignoreUndefined in initializeUnorderedBulkOp * initializeUnorderedBulkOp to honor ignoreUndefined All write operations (insertOne,update,updateMany etc...). honor the ignoreUndefined flag defined in the collection scope. Apparently UnorderedBulkOp was left out. This fixes it, makes UnorderedBulkOp honor the flag. * Fix lint * Add ignoreUndefined option to initializeOrderedBulkOp * Fix comment lower case * Give function's options precedence over session's options. --- lib/collection.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/collection.js b/lib/collection.js index 3726270363..b5b178276d 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -2048,11 +2048,17 @@ Collection.prototype.mapReduce = function(map, reduce, options, callback) { * @param {(number|string)} [options.w] The write concern. * @param {number} [options.wtimeout] The write concern timeout. * @param {boolean} [options.j=false] Specify a journal write concern. + * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. * @param {ClientSession} [options.session] optional session to use for this operation * @return {UnorderedBulkOperation} */ Collection.prototype.initializeUnorderedBulkOp = function(options) { options = options || {}; + // Give function's options precedence over session options. + if (options.ignoreUndefined == null) { + options.ignoreUndefined = this.s.options.ignoreUndefined; + } + options.promiseLibrary = this.s.promiseLibrary; return unordered(this.s.topology, this, options); }; @@ -2066,11 +2072,16 @@ Collection.prototype.initializeUnorderedBulkOp = function(options) { * @param {number} [options.wtimeout] The write concern timeout. * @param {boolean} [options.j=false] Specify a journal write concern. * @param {ClientSession} [options.session] optional session to use for this operation + * @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields. * @param {OrderedBulkOperation} callback The command result callback * @return {null} */ Collection.prototype.initializeOrderedBulkOp = function(options) { options = options || {}; + // Give function's options precedence over session's options. + if (options.ignoreUndefined == null) { + options.ignoreUndefined = this.s.options.ignoreUndefined; + } options.promiseLibrary = this.s.promiseLibrary; return ordered(this.s.topology, this, options); };