How to query the number of records of Filter's duplicate data in mongodb of node

do you want to query the number of records in a collection that are not duplicated by deptId?

the instruction db.model.distinct on the mongodb command line ("deptId"). Length can be implemented, but it can"t be used in node. How do you use it in node?

Oct.27,2021

db.collection("model").aggregate([
    {'$group': {_id: "$deptId"}}
]).then((err, c) => {
...
});
The distinct method under

shell is obsolete and is not recommended. It is believed that this method will be removed in a later version. But distinct is essentially group , which is the same in SQL, so just replace it with group .

Menu