From 473742f09a38dbdfb2a2006eec9907b142c243e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mu=C3=B1oz?= Date: Tue, 9 Jul 2019 15:18:36 -0400 Subject: [PATCH] cambio de condiciones se agrega para evitar sobrescritura en la query --- index.js | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cb2fea1..8c60e2b 100644 --- a/index.js +++ b/index.js @@ -58,7 +58,7 @@ module.exports = function(schema, options) { const parentDoc = isSubdocument ? this.ownerDocument() : this; const isNew = typeof parentDoc.isNew === "boolean" ? parentDoc.isNew : !isQuery; - const conditions = indexOptions.partialFilterExpression || {}; + let conditions = {}; each(paths, name => { let pathValue; @@ -113,6 +113,7 @@ module.exports = function(schema, options) { if (model.baseModelName && indexOptions.partialFilterExpression === null) { model = model.db.model(model.baseModelName); } + conditions = {$and: [conditions, indexOptions.partialFilterExpression || {}]}; model.find(conditions).countDocuments((err, count) => { resolve(count === 0); diff --git a/package.json b/package.json index 6ac59e6..e1ea15f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-unique-validator", - "version": "2.1.0", + "version": "2.1.1", "description": "mongoose-unique-validator is a plugin which adds pre-save validation for unique fields within a Mongoose schema.", "main": "index.js", "scripts": {