nodejs中利用mongoskin进行aggregate group操作,
exports.userStatistics = function(callback) {
var fromDate = new Date('2015-01-01T14:56:59.301Z');
db.collection('user').aggregate([ { $match : { "createDate" : { $gte : fromDate } } },{'$group': {_id: {year : { $year : "$createDate" },month : { $month : "$createDate" }},count: {$sum: 1}}},
{'$sort' : {'_id' : 1}}], function(err, data){
return callback(null, data);
});
};
exports.fruitStatistics = function(callback) {
db.collection('fruit').aggregate([ { $match : { "category": "apple" } }, {'$group': {_id: {year : { $year : "$datetime" },month : { $month : "$datetime" }},count: {$sum: 1}}},
{'$sort' : {'_id' : 1}}], function(err, data){
return callback(null, data);
});
};