Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-unique-validator

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-unique-validator - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

36

index.js

@@ -13,3 +13,3 @@ 'use strict';

if (indexOptions.unique) {
paths.forEach(function(path) {
paths.forEach(function(pathName) {
var pathMessage = message;

@@ -20,19 +20,23 @@ if (typeof indexOptions.unique === 'string') {

schema.path(path).validate(function(value, respond) {
var doc = this;
var path = schema.path(pathName);
var conditions = [];
paths.forEach(function(path) {
var condition = {};
condition[path] = doc[path];
conditions.push(condition);
});
if (path) {
path.validate(function(value, respond) {
var doc = this;
// Awaiting more official way to obtain reference to model.
// https://github.com/Automattic/mongoose/issues/3430
var model = doc.model(doc.constructor.modelName);
model.where({ $and: conditions }).count(function(err, count) {
respond(((doc.isNew && count === 0) || (!doc.isNew && count === 1)));
});
}, pathMessage);
var conditions = [];
paths.forEach(function(name) {
var condition = {};
condition[name] = doc[name];
conditions.push(condition);
});
// Awaiting more official way to obtain reference to model.
// https://github.com/Automattic/mongoose/issues/3430
var model = doc.model(doc.constructor.modelName);
model.where({ $and: conditions }).count(function(err, count) {
respond(((doc.isNew && count === 0) || (!doc.isNew && count <= 1)));
});
}, pathMessage);
}
});

@@ -39,0 +43,0 @@ }

{
"name": "mongoose-unique-validator",
"version": "0.5.0",
"version": "0.5.1",
"description": "mongoose-unique-validator is a plugin which adds pre-save validation for unique fields within a Mongoose schema.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc