From ba3137b1d1e4ac0c55de18980af43523a4a16273 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 13 Jan 2017 10:24:49 -0700 Subject: [PATCH] style: fix lint --- lib/aggregate.js | 10 +++--- lib/services/updateValidators.js | 2 +- test/model.test.js | 54 +++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/aggregate.js b/lib/aggregate.js index a72568a5373..28aa712a167 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -313,13 +313,13 @@ Aggregate.prototype.lookup = function(options) { /** * Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection. - * - * NOTE: graphLookup can only consume at most 100MB of memory, and does not allow disk use even if `{ allowDiskUse: true }` is specified. - * + * + * NOTE: graphLookup can only consume at most 100MB of memory, and does not allow disk use even if `{ allowDiskUse: true }` is specified. + * * #### Examples: * // Suppose we have a collection of courses, where a document might look like `{ _id: 0, name: 'Calculus', prerequisite: 'Trigonometry'}` and `{ _id: 0, name: 'Trigonometry', prerequisite: 'Algebra' }` * aggregate.graphLookup({ from: 'courses', startWith: '$prerequisite', connectFromField: 'prerequisite', connectToField: 'name', as: 'prerequisites', maxDepth: 3 }) // this will recursively search the 'courses' collection up to 3 prerequisites - * + * * @see $graphLookup https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/#pipe._S_graphLookup * @param {Object} options to $graphLookup as described in the above link * @return {Aggregate} @@ -335,7 +335,7 @@ Aggregate.prototype.graphLookup = function(options) { cloneOptions = utils.merge({}, options); var startWith = cloneOptions.startWith; - + if (startWith && typeof startWith === 'string') { cloneOptions.startWith = cloneOptions.startWith.charAt(0) === '$' ? cloneOptions.startWith : diff --git a/lib/services/updateValidators.js b/lib/services/updateValidators.js index 162ea73e5c4..f0fe613504f 100644 --- a/lib/services/updateValidators.js +++ b/lib/services/updateValidators.js @@ -37,7 +37,7 @@ module.exports = function(query, schema, castedDoc, options) { for (var j = 0; j < numPaths; ++j) { var updatedPath = paths[j].replace('.$.', '.0.'); updatedPath = updatedPath.replace(/\.\$$/, '.0'); - if (keys[i] === '$set' || keys[i] === '$setOnInsert') { + if (keys[i] === '$set' || keys[i] === '$setOnInsert' || keys[i] === '$push') { updatedValues[updatedPath] = flat[paths[j]]; } else if (keys[i] === '$unset') { updatedValues[updatedPath] = undefined; diff --git a/test/model.test.js b/test/model.test.js index 86ac83e933b..c424f25cff6 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -5223,29 +5223,45 @@ describe('Model', function() { }); it('insertMany() ordered option (gh-3893)', function(done) { - var schema = new Schema({ - name: { type: String, unique: true } + start.mongodVersion(function(err, version) { + if (err) { + done(err); + return; + } + var mongo34 = version[0] > 3 || (version[0] === 3 && version[1] >= 4); + if (!mongo34) { + done(); + return; + } + + test(); }); - var Movie = db.model('gh3893', schema); - var arr = [ - { name: 'Star Wars' }, - { name: 'Star Wars' }, - { name: 'The Empire Strikes Back' } - ]; - Movie.on('index', function(error) { - assert.ifError(error); - Movie.insertMany(arr, { ordered: false }, function(error) { - assert.equal(error.message.indexOf('E11000'), 0); - Movie.find({}).sort({ name: 1 }).exec(function(error, docs) { - assert.ifError(error); - assert.equal(docs.length, 2); - assert.equal(docs[0].name, 'Star Wars'); - assert.equal(docs[1].name, 'The Empire Strikes Back'); - done(); + function test() { + var schema = new Schema({ + name: { type: String, unique: true } + }); + var Movie = db.model('gh3893', schema); + + var arr = [ + { name: 'Star Wars' }, + { name: 'Star Wars' }, + { name: 'The Empire Strikes Back' } + ]; + Movie.on('index', function(error) { + assert.ifError(error); + Movie.insertMany(arr, { ordered: false }, function(error) { + assert.equal(error.message.indexOf('E11000'), 0); + Movie.find({}).sort({ name: 1 }).exec(function(error, docs) { + assert.ifError(error); + assert.equal(docs.length, 2); + assert.equal(docs[0].name, 'Star Wars'); + assert.equal(docs[1].name, 'The Empire Strikes Back'); + done(); + }); }); }); - }); + } }); it('insertMany() hooks (gh-3846)', function(done) {