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

mongoose-unique-validator

Package Overview
Dependencies
Maintainers
1
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.1.2 to 0.2.0

9

index.js

@@ -1,6 +0,5 @@

module.exports = function (schema, options) {
var mongoose = options.mongoose;
module.exports = function (schema) {
schema.eachPath(function (path, schemaType) {
if (schemaTypeHasUniqueIndex(schemaType)) {
var validator = buildUniqueValidator(path, mongoose);
var validator = buildUniqueValidator(path);
schemaType.validate(validator, 'unique');

@@ -15,5 +14,5 @@ }

function buildUniqueValidator(path, mongoose) {
function buildUniqueValidator(path) {
return function (value, respond) {
var model = mongoose.connection.model(this.constructor.modelName);
var model = this.model(this.constructor.modelName);
var query = buildQuery(path, value, this._id);

@@ -20,0 +19,0 @@ var callback = buildValidationCallback(respond);

{
"name": "mongoose-unique-validator",
"version": "0.1.2",
"version": "0.2.0",
"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",

@@ -17,3 +17,3 @@ mongoose-unique-validator

Simply apply the plugin to your schema and pass in your `mongoose` instance:
Then, simply apply the plugin to your schema:

@@ -25,3 +25,3 @@ ```js

var mySchema = mongoose.Schema(/* put your schema definition here */);
mySchema.plugin(uniqueValidator, { mongoose: mongoose });
mySchema.plugin(uniqueValidator);
```

@@ -47,3 +47,3 @@

// Apply the uniqueValidator plugin to userSchema.
userSchema.plugin(uniqueValidator, { mongoose: mongoose });
userSchema.plugin(uniqueValidator);
```

@@ -50,0 +50,0 @@

@@ -22,3 +22,3 @@ // TODO Fix callback hell with Q promise library.

});
userSchema.plugin(uniqueValidator, { mongoose: mongoose });
userSchema.plugin(uniqueValidator);
var User = mongoose.model('User', userSchema);

@@ -25,0 +25,0 @@

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