how to use unique validator in mongoose code example
Example: mongoose unique validator
npm install --save mongoose-unique-validator
var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var mySchema = mongoose.Schema(/* put your schema definition here */);
mySchema.plugin(uniqueValidator);