Mongodb聚合操作
1、
sql语句
select code,count(*) from user group by code having count(*)>2
mongodb脚本
db.user.aggregate([{$group:{_id:'$code',count:{$sum:1}}},{$match:{count:{$gte:2}}}]);
2、
sql语句
select count(distinct name) from user 对应如下
mongodb脚本
db.user.distinct("name").length