Skip to content

Commit

Permalink
fix conditions that changes "conditions" variable.
Browse files Browse the repository at this point in the history
early return for check _id in old document.
simplify model detection.
  • Loading branch information
Juan Carlos Muñoz committed Apr 17, 2019
1 parent b8f3e0f commit c1e8db6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ module.exports = function(schema, options) {
each(this._conditions, (value, key) => {
conditions[key] = { $ne: value };
});
} else if (this._id) {
} else if (pathName !== '_id') {
// if it's not new then it always has _id
conditions._id = { $ne: this._id };
} else {
// if is not new and is not query and the pathName is _id then is the same document no need to check anything
return resolve(true);
}
}

Expand All @@ -97,8 +101,9 @@ module.exports = function(schema, options) {
model = this.model;
} else if (isSubdocument) {
model = this.ownerDocument().model(this.ownerDocument().constructor.modelName);
} else if (isFunc(this.model)) {
model = this.model(this.constructor.modelName);
} else if (this.constructor.modelName) {
// if the constructor has modelName then the constructor is the model
model = this.constructor;
}

// Is this model a discriminator and the unique index is on the whole collection,
Expand Down

0 comments on commit c1e8db6

Please sign in to comment.