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

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