所以我需要在我的数据库中获取用户帖子的类别中的排名和总数。例如,所需的输出可能是
Hi bob, here are your posts rankings:
'Breaking News' is ranked #10 of 203 in the 'news' category
'Day at the Game' is ranked #24 of 67 in the 'sports' category".
这是架构
PostSchema = new Schema({
{
score:Number,
categoryId: ObjectId,
categoryName: String,
title: String,
username: String
}
});
示例帖子
{ score: 12,
categoryId:"50cf7d2841d41f4f35000000",
categoryName:"sports",
title:"Day at the Game",
username:"bob"
}
我想我可以在 map reduce 中尝试这个,但是有没有使用聚合命令的方法?什么是最有效的 map reduce 函数?