title: How to stop insertion of Duplicate documents in a mongodb collection
body: <p>Let us have a <code>MongoDB</code> collection which has three docs..</p>
  
  <p>db.collection.find()</p>
  
  <pre><code> { _id:'...', user: 'A', title: 'Physics',   Bank: 'Bank_A' }
   { _id:'...', user: 'A', title: 'Chemistry', Bank: 'Bank_B' }
   { _id:'...', user: 'B', title: 'Chemistry', Bank: 'Bank_A' }
  </code></pre>
  
  <p>We have a doc,</p>
  
  <pre><code> doc = { user: 'B', title: 'Chemistry', Bank:'Bank_A' }
  </code></pre>
  
  <p>If we use </p>
  
  <pre><code> db.collection.insert(doc) 
  </code></pre>
  
  <p>here, this duplicate doc will get inserted in database. </p>
  
  <pre><code> { _id:'...', user: 'A', title: 'Physics',   Bank: 'Bank_A' }
   { _id:'...', user: 'A', title: 'Chemistry', Bank: 'Bank_B' }
   { _id:'...', user: 'B', title: 'Chemistry', Bank: 'Bank_A' }
   { _id:'...', user: 'B', title: 'Chemistry', Bank: 'Bank_A' }
  </code></pre>
  
  <p>How this duplicate can be stopped. On which field should indexing be done or any other approach?</p>