title: PyMongo statistics
body: <p>I am using PyMongo and have a collection with about 5 million entries. Each entry has a country code field.</p>
  
  <p>What is the most elegant way (and best performance-wise?) to get a statistics like:</p>
  
  <pre><code>US - 302000
  CA - 180000
  IN - 160000
  DE - 125000
  ...
  </code></pre>
  
  <p>Does MongoDB have a special kind of query for that or should I do it in a loop with an ordinary Python dictionary?</p>
  
  <p>edit:
  example of an entry:</p>
  
  <pre><code>update(
      {"id": user["id"]},
      {"$set": {
          ... some other fields
          "_country_code": "US",
          "_last_db_update": datetime.datetime.utcnow()}
      }, upsert=True)
  </code></pre>