我使用 Meteor 和 MongoDB 。我需要使用聚合发布(我使用 jcbernack:reactive-aggregate 和 ReactiveAggregate )。
db.getCollection('Jobs').aggregate([
{
$lookup:
{
from: "JobMatches",
localField: "_id",
foreignField: "jobId",
as: "matches"
}
},
{ $project:
{
matches: {
'$filter': {
input: '$matches',
as: 'match',
cond: { '$and': [{$eq: ['$$match.userId', userId]}]}
}
}
}
},
{$match: { 'matches.score': { '$gte': 60 }},
{$sort: { "matches.score": -1 }},
{$limit: 6}
])
在客户端,我只获得数据部分(限制6)。所以我将不得不计算服务器端所有数据的数量。我无法使用find().count()
,因为在没有聚合的find()
调用中,我无法使用与其他集合关联的过滤器(例如此{ 'matches.score': { '$gte': 60 }
)。如何计算以这种方式过滤的数据?可能需要在管道中使用 $ group ?