title: MongoDB distinct aggregation
body: <p>I'm working on a query to find cities with most zips for each state:</p>
  <pre><code>db.zips.distinct(&quot;state&quot;, db.zips.aggregate([ 
      { $group:
        { _id: {
             state: &quot;$state&quot;, 
             city: &quot;$city&quot; 
           },
          numberOfzipcodes: { 
             $sum: 1
           }
        }
      }, 
      { $sort: {
          numberOfzipcodes: -1
           }
        }
    ])
  )
  </code></pre>
  <p>The aggregate part of the query seems to work fine, but when I add the distinct I get an empty result.</p>
  <p>Is this because I have state in the id? Can I do something like <code>distinct(&quot;_id.state</code> ?</p>