“Mongoose Validator Unik” Kode Jawaban

Mongoose bidang unik

var SimSchema = new Schema({
    msisdn     : { type : String , unique : true, required : true, dropDups: true },
    imsi       : { type : String , unique : true, required : true, dropDups: true },
    status     : { type : Boolean, default: true},
    signal     : { type : Number },
    probe_name : { type:  String , required : true }
});
Worrisome Wallaby

Mongoose Validator Unik

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);
Hastings Keith

Mongoose pesan kesalahan unik

emailVerificationTokenSchema.post('save', function(error, doc, next) {
  if (error.name === 'MongoError' && error.code === 11000) {
    next(new Error('email must be unique'));
  } else {
    next(error);
  }
});
Worrisome Wallaby

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);
Nasty Newt

Validator ID Mongoose

var mongoose = require('mongoose');
var isValid = mongoose.Types.ObjectId.isValid('5c0a7922c9d89830f4911426'); //true
Salo Hopeless

Jawaban yang mirip dengan “Mongoose Validator Unik”

Pertanyaan yang mirip dengan “Mongoose Validator Unik”

Lebih banyak jawaban terkait untuk “Mongoose Validator Unik” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya