title: Can MongoDB aggregate "top x" results in this document schema?
body: <pre><code>{
      "_id" : "user1_20130822",
      "metadata" : {
          "date" : ISODate("2013-08-22T00:00:00.000Z"),
          "username" : "user1"
      },
      "tags" : {
          "abc" : 19,
          "123" : 2,
          "bca" : 64,
          "xyz" : 14,
          "zyx" : 12,
          "321" : 7
      }
  }
  </code></pre>
  
  <p>Given the schema example above, is there a way to query this to retrieve the top "x" tags:  E.g.,  Top 3 "tags" sorted descending?</p>
  
  <p>Is this possible in a single document?  e.g., top tags for a user on a given day
  What if i have multiple documents that need to be combined together before getting the top?  e.g., top  tags for a user in a given month</p>
  
  <p>I know this can be done by using a "document per user per tag per day" or by making "tags" an array, but I'd like to be able to do this as above, as it makes in place $inc's easier (many more of these happening than reads).</p>
  
  <p>Or do I need to return back the whole document, and defer to the client on the sorting/limiting?</p>