要查詢一個collection中deptId不重復(fù)的記錄數(shù)?mongodb命令行中的指令db.model.distinct("deptId").length可以實(shí)現(xiàn),但是在node中無法使用,大家在node中是怎么使用的那?
1 回答

胡子哥哥
TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個贊
db.collection("model").aggregate([ {'$group': {_id: "$deptId"}} ]).then((err, c) => { ... });
shell下面的distinct
方法已經(jīng)過時不建議使用,相信后面的版本會移除此方法。不過distinct
本質(zhì)上就是group
,這在SQL中也是一樣,所以換成group
就好了。
- 1 回答
- 0 關(guān)注
- 553 瀏覽
添加回答
舉報
0/150
提交
取消