title: mongoDb/Mongoose: make emailId unique field
body: <p>I am trying to make email field as unique on database level. When a new document is created with same emailId it should throw an error. 
  To implement it I am using 
  <code>email : {type: String, trim: true, index: true, unique: true, sparse: true,required: true}</code></p>
  
  <p>But it doesn't seem to be working , currently it is adding new documents with same emailId.</p>
  
  <p>Referred this post : <a href="https://stackoverflow.com/questions/7955040/mongodb-mongoose-unique-if-not-null">mongoDB/mongoose: unique if not null</a></p>
  
  <p>Checked <code>.getIndexes()</code> and this is the output of it :</p>
  
  <p><a href="https://i.stack.imgur.com/hn1av.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hn1av.png" alt="enter image description here"></a></p>