diff --git a/index.js b/index.js index 38cfc1a..b10acfb 100644 --- a/index.js +++ b/index.js @@ -116,7 +116,7 @@ module.exports = function (schema, options) { if (model.baseModelName && indexOptions.partialFilterExpression === null) { model = model.db.model(model.baseModelName); } - conditions = {...indexOptions.partialFilterExpression, ...conditions}; + conditions = {$and: [conditions, indexOptions.partialFilterExpression || {}]}; const count = await model.find(conditions).countDocuments(); return count === 0; diff --git a/package.json b/package.json index 680d510..7ee76b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-unique-validator", - "version": "3.0.1", + "version": "3.0.2", "description": "mongoose-unique-validator is a plugin which adds pre-save validation for unique fields within a Mongoose schema.", "main": "index.js", "scripts": {