title: running a $sum query on a set that uses a 2GB index causes 20GB of memory usage
body: <p>I've got a large-ish set of records (100M) that look like: </p>
  
  <pre><code>/* 0 */
  {
      "entry_dt" : ISODate("2012-10-19T02:01:35.176Z"),
      "val" : 13.78,
      "order" : {
          "id" : "85PVSQRS4O",
          "orig_dt" : ISODate("2012-10-19T01:25:35.176Z"),
          "discount" : 2.56,
          "year" : 2013,
          "month" : 10,
          "day" : 19,
          "hour" : 25,
          "minute" : 25,
          "dayOfWeek" : 5,
          "week" : 42,
          "quarter" : 3
      }
      "_id" : ObjectId("52e6ed219cea5b5c64c08d8e")
  }
  </code></pre>
  
  <p>I'm stress testing the app for max record count per server, memory usage and speed. I pull up the index stats and see that the index on <code>order.year</code> is 2400MB. I've got about 40GB of mem on the server. So I run a simple aggregtion: </p>
  
  <pre><code>db.data.aggregate(
      [
          {"$match":{"$and":[{"order.year":2013}]}},
          {"$limit": 1000},
          {"$project":{"v":"$v", "year": "$order.year"}},
          {"$group":{"_id":"$year","v":{"$sum":"$v"}}},
          {"$sort":{"_id":1}}
      ]
  )
  </code></pre>
  
  <p>(note: this query is being generated from a query object, so might need some tuning)</p>
  
  <p>Comes back in 14ms. So I decide to run it over the whole dataset and WHAM it goes south really fast. If I just let it chunk away it'll take about 10 minutes. What I see is that the memory is going from &lt;1GB to 20GB (which is taking total mem used to 95%). </p>
  
  <p>Db stats: </p>
  
  <pre><code>&gt; db.data.stats()
  ...
  {
  "indexSizes" : {
  ...
  "order.year_1" : 2516646384,
  </code></pre>
  
  <p>Did I write the query wrong? Why would running a query on an index that is reasonably sized take up so much RAM? </p>