title: How to remove duplicates based on a key in Mongodb?
body: <p>I have a collection in MongoDB where there are around (~3 million records). My sample record would look like,</p>
  
  <pre><code> { "_id" = ObjectId("50731xxxxxxxxxxxxxxxxxxxx"),
     "source_references" : [
                             "_id" : ObjectId("5045xxxxxxxxxxxxxx"),
                             "name" : "xxx",
                             "key" : 123
                            ]
   }
  </code></pre>
  
  <p>I am having a lot of duplicate records in the collection having same <code>source_references.key</code>. (By Duplicate I mean, <code>source_references.key</code> not the <code>_id</code>).</p>
  
  <p>I want to remove duplicate records based on <code>source_references.key</code>, I'm thinking of writing some PHP code to traverse each record and remove the record if exists.</p>
  
  <p>Is there a way to remove the duplicates in Mongo Internal command line?</p>