title: In MongoDB, how to use the aggregation framework to have little docs
body: <p>i'm trying to play with the aggregation framework but i have an issue.
  I need to known how many people in my database have purchase something during the last month.</p>
  
  <p>To do that i use this : </p>
  
  <pre><code>db.account.aggregate([
  {$project : {civility : 1, 'purchase.date' : 1 }},
  {$match: {civility : 1 ,'purchase.date': {$gte: new Date('02/02/2013'), $lt: new Date('02/03/2013')} }},
  {$unwind: '$purchase'},
  {$match: {civility : 1 ,'purchase.date': {$gte: new Date('02/02/2013'), $lt: new Date('02/03/2013')} }},
  {$group: {_id: '$_id', total_buy : {$sum : 1}}},
  {$match: {total_buy: {$gte: 2}}},
  {$group: {_id: null, total_buyer : {$sum : 1}}}
  ])
  </code></pre>
  
  <p>I have this response</p>
  
  <pre><code>{
  "result" : [
  {
  "_id" : null,
  "total_buyer" : 4443
   }
  ],
  "ok" : 1
  }
  </code></pre>
  
  <p>this query work because the range of date I use use is small but if i use the same query with a range of date wich is larger like this : </p>
  
  <pre><code>db.account.aggregate([
  {$project : {civility : 1, 'purchase.date' : 1 }},
  {$match: {civility : 1 ,'purchase.date': {$gte: new Date('02/01/2013'), $lt: new     Date('03/01/2013')} }},
  {$unwind: '$purchase'},
  {$match: {civility : 1 ,'purchase.date': {$gte: new Date('02/01/2013'), $lt: new    Date('03/01/2013')} }},
  {$group: {_id: '$_id', total_buy : {$sum : 1}}},
  {$match: {total_buy: {$gte: 2}}},
  {$group: {_id: null, total_buyer : {$sum : 1}}}
  ])
  </code></pre>
  
  <p>i have this : </p>
  
  <pre><code>{
  "errmsg" : "exception: sharded pipeline failed on shard shard0000: { errmsg: \"exception: aggregation result exceeds maximum document size (16MB)\", code: 16389, ok: 0.0 }",
  "code" : 16390,
  "ok" : 0
  }
  </code></pre>
  
  <p>is there something i do wrong or i can't do what i need to do ?</p>
  
  <p>thanks in advance</p>