Skip to content

Commit

Permalink
style: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 13, 2017
1 parent 76f4bff commit ba3137b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
10 changes: 5 additions & 5 deletions lib/aggregate.js
Expand Up @@ -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}
Expand All @@ -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 :
Expand Down
2 changes: 1 addition & 1 deletion lib/services/updateValidators.js
Expand Up @@ -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;
Expand Down
54 changes: 35 additions & 19 deletions test/model.test.js
Expand Up @@ -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) {
Expand Down

0 comments on commit ba3137b

Please sign in to comment.