MongoDB 聚合内排序


MongoDB 聚合内排序

把分组的主键都归在一起,再去聚合排序

1
2
3
4
5
var group = {_id:{playerId:"$playerId"},
obj:{$push: {id:"$id",title:"$title",playerId: "$playerId",date: "$date"}},
dateMax: {$max: "$date"},count:{$sum:1}};

db.xxx.aggregate([{$sort:{playerId:1,date:-1}}, {$group: group},{$sort:{dateMax:-1}},{$skip:1*50},{$limit:50}]);