Node.js 2018年NodeJS Express Mongoose API的MongoDB独特计数

Node.js 2018年NodeJS Express Mongoose API的MongoDB独特计数,node.js,mongodb,api,express,mongoose,Node.js,Mongodb,Api,Express,Mongoose,我试图获得这个值(db.collecName.distinct('fieldName').length)基本上是一个不同文档的计数,但是在ReactJS Express Mongoose API路由中 应采用以下API调用格式: router.get('/', function(req, res, next){ ModelName.find(function (err, CollecName){ if(err) return next(err); res.json

我试图获得这个值(db.collecName.distinct('fieldName').length)基本上是一个不同文档的计数,但是在ReactJS Express Mongoose API路由中

应采用以下API调用格式:

router.get('/', function(req, res, next){
    ModelName.find(function (err, CollecName){
      if(err) return next(err);
      res.json(CollecName);
    });
});
提前谢谢

感谢Jeremy T

router.get('/count', function(req, res, next){
    ModelName.find().distinct('fieldName', function(err, Response) {
        if (err) return next(err);
        // console.log(Response.length);
        res.json(Response.length);
    });
});

~SOLUTION

我不明白。如果您试图获得
db.collecName.distinct('fieldName')
,那么为什么不在代码中使用它呢?我不知道如何正确地编码它,所以我想我会征求有关结构的想法。好吧,你得到了。你在问题中给出了答案。你有代码,只是因为某些原因没有尝试。看看这里:谢谢Jeremy,这些代码足以帮助我写下我需要的东西。