0
這個Meteor服務器代碼嘗試對文檔進行分組並按屬性「period」對其進行排序,但它沒有這樣做,任何想法如何解決它? THX如何對文件進行排序:聚合輸出
let invoicePopulation = UsageCol.aggregate([
{
$match: {
action: {$in: ['a', 'b', 'c']},
userId: doc.userId
}
},
{
$group: {
_id: {period: "$period"},
count: {$sum: 1}
}
},
{
"$sort" : {
"period" : 1
}
}
]);
//output
[{"_id":{"period":"42017"},"count":14},{"_id":{"period":"22017"},"count":1},{"_id":{"period":"32017"},"count":271}]
//needs to be
[{"_id":{"period":"22017"},"count":1},{"_id":{"period":"32017"},"count":271},{"_id":{"period":"42017"},"count":14}]