title: MongoDB - Find duplicated elements in record property
body: <p>I'm struggling to identified duplicated elements in my MongoDB records, here is my problem :</p>
  
  <p>I have a Mongo collection named "elements".</p>
  
  <p>Example of a record in this collection :</p>
  
  <pre><code>{
      "_id" : ObjectId("5d1b2204e851271e80c824b6"),
      "name" : "A",
      "items" : [ 
          {
              "ref_id" : ObjectId("5d1b2204e851271e80c823d7"),
              "_id" : ObjectId("5d1b2205e851271e80c82534")
          }, 
          {
              "ref_id" : ObjectId("5d1b2204e851271e80c823d6"),
              "_id" : ObjectId("5d1b2205e851271e80c82533")
          }, 
          {
              "ref_id" : ObjectId("5d1b2204e851271e80c823d8"),
              "_id" : ObjectId("5d1b2205e851271e80c82532")
          }, 
          {
              "ref_id" : ObjectId("5d1b2204e851271e80c823d5"),
              "_id" : ObjectId("5d1b3048e851271e80c826a5")
          }, 
          {
              "ref_id" : ObjectId("5d1b2204e851271e80c823d5"),
              "_id" : ObjectId("5d1b3048e851271e80c826ad")
          }
      ]
  }
  </code></pre>
  
  <p>I would like to identify records where the array "items" contains objects with the same "ref_id". </p>
  
  <p>In my example we can see that the last two objects of the "items" array have the same "ref_id" : <strong>ObjectId("5d1b2204e851271e80c823d5")</strong>.</p>
  
  <p>I tried a bunch of aggregate function but unfortunately couldn't came out with a solution.</p>