mongodb - Mongo aggregate query pulling out last 7 days worth of data (node.js) -
mongodb - Mongo aggregate query pulling out last 7 days worth of data (node.js) -
i have big collection of info i'm trying pull out of mongo (node js) in order render graphs.
i need pull lastly 7 days worth of info out of few one thousand users. specific piece of info on each user formatted so:
{ "passedmodules" : [{ "module" : objectid("53ea17dcac1d13a66fb6d14e"), "date" : isodate("2014-09-17t00:00:00.000z") }, { "module" : objectid("53ec5c91af2792f1112554e8"), "date" : isodate("2014-09-17t00:00:00.000z") }, { "module" : objectid("53ec5c5baf2792f1112554e6"), "date" : isodate("2014-09-17t00:00:00.000z") }] }
at moment have messy grouping of queries working, believe possible exclusively mongo?
basically, need pull out entries 7 days ago until now, in dynamic fashion.
is there tried , testing way of working dynamic dates in way, more using aggregation framework in mongo? reason aggregation framework need grouping these afterwards.
many thanks
the general pattern type of query is:
// compute time 7 days ago utilize in filtering info var d = new date(); d.setdate(d.getdate()-7); db.users.aggregate([ // include docs have @ to the lowest degree 1 passedmodules element // passes filter. {$match: {'passedmodules.date': {$gt: d}}}, // duplicate docs, 1 per passedmodules element {$unwind: '$passedmodules'}, // filter 1 time again remove non-matching elements {$match: {'passedmodules.date': {$gt: d}}} ])
node.js mongodb mongoose aggregation-framework
Comments
Post a Comment