9

这是它的样子 -

db.log.aggregate({
  $match:{ v:1, t:"trainingStep" },
  $group:{ _id:{userId:'$u',questionId:'$s'}, counts:{$sum:1} },
  $match:{ 'counts':{$gte:2} }
})
  1. 第一场比赛完美无缺。
  2. 该小组工作完美,并推出了我正在寻找的东西。
  3. 最后一个 $match 不起作用并显示所有计数而不是我请求的 >=2

我试过'counts'、'$counts'、“$counts”......但没有一个成功!

4

1 回答 1

23

Each of the operators in your aggregate pipeline need to be separate objects. Also, while some versions of the shell (and drivers) may allow passing the objects as separate parameters, the correct way is to pass them wrapped in a single array. Try this instead:

db.log.aggregate([
  { $match: { v: 1, t: "trainingStep" } },
  { $group: { _id: {userId: '$u', questionId: '$s'}, counts: {$sum: 1} } },
  { $match: { 'counts': {$gte: 2} } }
])
于 2012-10-30T19:34:51.983 回答