title: group by and delete documents based on a field array size
body: <p>I have documents like this:</p>
  
  <pre><code>{
      "_id" : ObjectId("53bcedc39c837bba3e1bf1c2"),
      id : "abc1",
      someArray: [ 1 , 10 , 11]
  }
  
  {
      "_id" : ObjectId("53bcedc39c837bba3e1bf1c4"),
      id : "abc1",
      someArray: [ 1 , 10]
  }
  ... other similar documents with different Ids
  </code></pre>
  
  <p>I would like to go through the whole collection and delete the document where <code>someArray</code> is smallest, grouped by <code>id</code>. So in this example, I group by <code>abc1</code> (and I get 2 documents) and then the 2nd document would be the one to delete because it has least count in <code>someArray</code>. </p>
  
  <p>There isn't a <code>$count</code> accumulator so I don't see how I can use <code>$group</code>. </p>
  
  <p>Additionally, there will be 1000s of Ids that have duplicates like this, so if there is such a thing as a bulk check/delete that would be good (possibly a stupid question, sorry, Mongo is all new to me!)</p>