title: How to avoid duplicate entries in mongoose
body: <p>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 <code>serverIP</code>, for that <code>unique : true</code> is added. But this is not working as expected and duplicates entries are getting through.</p>
  
  <p>Below is the example code:-</p>
  
  <pre><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}
  });
  </code></pre>
  
  <p>I've checked <a href="https://stackoverflow.com/questions/12191311/mongodb-avoid-duplicate-entries">CreateIndex</a> functionality for this but don't know how to implement this with my code.</p>
  
  <p>I have never worked on back-end part, so please excuse if this is a novice question.</p>