title: Mongoose vs MongoDB validation
body: <p>I have a project I am working on and was following a guide for user creation. The goal was to create a user with a unique username and unique email and bcrypt password. No other user should be able to sign up using either the username or email, once one is used. </p>
  
  <p>The process involved creating the user, using the below Schema via a Post request, using postman. The "unique" indicator was added after a user had already been created. After I updated the Schema to include the "unique" option, I found that users could still be created with the same email. While searching on here I found that was due to the initial documents being created with that email and that was resolved by removing that collection and starting fresh, not a big problem.</p>
  
  <pre><code>var UserSchema = new Schema({
  username: { type: String, lowercase: true, required: true, unique: 
  true},
  password: { type: String, required: true },
  email: { type: String, required: true, lowercase: true, unique: true}
  });
  </code></pre>
  
  <p>However, while researching the Mongoose website I found some info on validation that has left me a bit confused. I was looking at the <a href="https://mongoosejs.com/docs/validation.html" rel="nofollow noreferrer">validation</a> docs and then <a href="https://mongoosejs.com/docs/faq.html" rel="nofollow noreferrer">FAQ</a> on the Mongoose site which from what I can tell states I should instead, in production, use MongoDB shell to <a href="https://docs.mongodb.com/manual/core/index-unique/" rel="nofollow noreferrer">create the indexes</a> for my data, if I want them to be confirmed unique on creation, instead of using the "unique" option. </p>
  
  <p>Is this correct? Or, why would I ever use "unique" in Mongoose when Mongoose is telling me that in the end I will actually need to use MongoDB Shell? With the <a href="https://docs.mongodb.com/manual/core/schema-validation/" rel="nofollow noreferrer">Schema validation available in MongoDB</a> is Mongoose still a preferred option to use when developing MEAN apps, today? I do see Mongoose frequently used but I don't have any huge opinions or need to make something as relational as possible, is Mongoose still worth learning over just using MongoDB itself? If I am so wrong it hurts that is fine and I can accept that but any insight would be appreciated.</p>