Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like there are a couple of things you can do to improve your aggregation:</p> <p>1) add a <code>$project</code> to avoid passing through fields which you have already used (everything but the <code>_id</code></p> <p>2) you say you want number of buyers who bought anything but you are filtering to only keep buyers who bought two or more "times" or "things" during the time period.</p> <p>Result:</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')} }}, {$project: {_id :1}}, {$group: {_id: '$_id', total_buys : {$sum : 1}}}, {$group: {_id: null, total_buyers : {$sum : 1}}} ]) </code></pre> <p>Given the size of your <code>_id</code> field, that should work in current version (2.4) as long as each shard matches no more than about 420,000 documents. With each document representing a purchase, I suspect you may still run into a limit, so you have several choices:</p> <p>1) wait till 2.6 (currently available as unstable development release 2.5.2) which eliminates the restriction on size of data set (here it's not the final size, but the size that shard0000 must pass back to mongos that's the issue). 2) use a different method to count distinct buyers during particular time period (if that's what you really want - that's not quite what your original aggregation is counting).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload