title: Find all duplicate documents in a MongoDB collection by a key field
body: <p>Suppose I have a collection with some set of documents. something like this.</p>
  
  <pre><code>{ "_id" : ObjectId("4f127fa55e7242718200002d"), "id":1, "name" : "foo"}
  { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":2, "name" : "bar"}
  { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":3, "name" : "baz"}
  { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":4, "name" : "foo"}
  { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":5, "name" : "bar"}
  { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":6, "name" : "bar"}
  </code></pre>
  
  <p>I want to find all the duplicated entries in this collection by the "name" field. E.g. "foo" appears twice and "bar" appears 3 times.</p>