title: Recommended approach to avoid duplicating username in MongoDB
body: <p>When a new user attempts to register on my application at present, part of the validation process is to check against the database (MongoDB) whether the username and email are already in use. This validation process is part of my application logic.</p>
  
  <p>I would like to know whether it's possible/better to attempt to save the user without these validation checks and let the DB detect an error (due to duplicated email address or username) which I could then handle.</p>
  
  <p>If so, how could I handle these errors so that I could handle each (username and email). Something in the fashion of...</p>
  
  <pre><code>err := c.Database.C("users").Insert(&amp;user);
  if err != nil {
      //check whether issue is with email or username or both
  }
  </code></pre>