I am trying to play with an aggregation base, but I have a problem. I need to know how many people in my database have purchased something in the last month.
For this, I use this:
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}}} ])
I have this answer
{ "result" : [ { "_id" : null, "total_buyer" : 4443 } ], "ok" : 1 }
this query works because the date range of the date I'm using is small, but if I use the same query with a date range that is larger than this:
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}}} ])
I have it:
{ "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 }
is there something i'm doing wrong or can i not do what i need to do?
early