我有以下集合,代表会员去健身房时的滑动记录。我希望在给定月份的滑动次数之后返回成员的等级。
{
"_id" : ObjectId(""),
"content" : {
"Date_Key" : "",
"TRANSACTION_EVENT_KEY" : "",
"SITE_NAME" : "",
"Swipe_DateTime" : "",
"Gender" : "",
"Post_Out_Code" : "",
"Year_Of_Birth" : "",
"Time_Key" : "",
"MemberID_Hash" : "",
"Member_Key_Hash" : "",
"Swipes" : ""
},
"collection" : "observations"
}
我有以下聚合,它返回更高级别的成员(因此,更频繁去过健身房的成员)
collection
.aggregate(
[{$match: {"content.Swipe_DateTime": {$regex:"201602"}}},
{$group: {_id: "$content.MemberID_Hash", count:{$sum: 1}}},
{$sort: {count: 1}},
{$match: {count: {$gte: user_swipes_month}}}],
function(err,result) {
console.log("User's Rank: ", result[0].count);
});
然后我的问题是,我如何计算返回的数字或行数?我试过做另一个小组,但我认为根据得到的结果它是不正确的。
collection
.aggregate(
[{$match: {"content.Swipe_DateTime": {$regex:"201602"}}},
{$group: {_id: "$content.MemberID_Hash", count:{$sum: 1}}},
{$sort: {count: 1}},
{$match: {count: {$lte: user_swipes_month}}},
{$group: {_id: null, count:{$sum: 1}}}],
function(err,result) {
console.log("User's Rank: ", result[0].count);
});
我有什么想法/建议可以解决这个问题吗?