diff --git a/lib/collection.js b/lib/collection.js index 067cb4dbaf..9922f16173 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -686,7 +686,15 @@ Collection.prototype.updateOne = function(filter, update, options, callback) { if (typeof options === 'function') (callback = options), (options = {}); options = options || {}; - const err = checkForAtomicOperators(update); + let err; + if (Array.isArray(update)) { + for (let i = 0; !err && i < update.length; i++) { + err = checkForAtomicOperators(update[i]); + } + } else { + err = checkForAtomicOperators(update); + } + if (err) { if (typeof callback === 'function') return callback(err); return this.s.promiseLibrary.reject(err); diff --git a/test/functional/collection_tests.js b/test/functional/collection_tests.js index dd06ac44e6..44f28a5525 100644 --- a/test/functional/collection_tests.js +++ b/test/functional/collection_tests.js @@ -1898,4 +1898,36 @@ describe('Collection', function() { } }); }); + + it('should correctly update with pipeline', { + metadata: { + requires: { mongodb: '>=4.2.0' } + }, + + // The actual test we wish to run + test: function(done) { + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { + poolSize: 1 + }); + + client.connect((err, client) => { + const db = client.db(configuration.db); + + db.createCollection('test_should_correctly_do_update_with_pipeline', (err, collection) => { + collection.updateOne( + {}, + [{ $set: { a: 1 } }, { $set: { b: 1 } }, { $set: { d: 1 } }], + configuration.writeConcernMax(), + (err, r) => { + expect(err).to.not.exist; + expect(r.result.n).to.equal(0); + + client.close(done); + } + ); + }); + }); + } + }); });