I'm creating a new schema in mongoose and trying to take input from user. I want that no duplicate entry is getting updated for serverIP
, for that unique : true
is added. But this is not working as expected and duplicates entries are getting through.
Below is the example code:-
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ServerSchema = new Schema({
serverIp: { type : String , unique : true },
Name: { type: String },
serverType: {type: String , required : true },
created_date: {type: Date, default: Date.now},
updated_date: {type: Date, default: Date.now}
});
I've checked CreateIndex functionality for this but don't know how to implement this with my code.
I have never worked on back-end part, so please excuse if this is a novice question.