reew 发表于 2016-4-15 10:42:12

【MongoDB】使用aggregate求最大值

mongo aggregate查询:

1
2
3
4
5
6
7
db.collection.aggregate({
    $group:{
      _id:"$id",//"$_id"代表引用集合中_id列
      max_value:{$max:"$times"} //"$times"代表引用集合中times列
    },
    $match:{times:{$gte:100}}
})





相当于sql查询:

1
2
3
select _id, max(times)
from collection
where times>=100



页: [1]
查看完整版本: 【MongoDB】使用aggregate求最大值