假设我有这个Mongoose查询:
const actors = await Actor.aggregate([{ "$group": {_id: "$loc.coordinates", count:{$sum:1}} }])
有没有办法只得到 actors 有一个 count > 1 ?
actors
count > 1
使用 $match 之后的阶段 $group
$match
$group
const actors = await Actor.aggregate([ { "$group": { "_id": "$loc.coordinates", "count": { "$sum": 1 }} }, { "$match": { "count": { "$gt": 1 }} } ])