当前位置: 首页 > 工具软件 > mongoskin > 使用案例 >

mongoskin aggregate group

姬康平
2023-12-01

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);
    });
};




 类似资料:

相关阅读

相关文章

相关问答