UnhandledPromiseRejectionWarning没有达到Catch

时间:2019-04-07 14:12:57

标签: mongodb

这是我的代码:

db.Registration.model.countDocuments()
.then(function (count) {
    return res.status(200).send({ count });
})
.catch(function (err) {
    console.log('errrr', err);
    if (err)
        return res.status(500).sendStatus(err);
    else
        return res.status(200).sendStatus({ count });
})

我收到以下错误:

Express server running on *:5000
(node:8864) UnhandledPromiseRejectionWarning: Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-shard-00-00-jjbdh.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:196:19)
(node:8864) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8864) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

为什么catch不起作用,却出现此错误?

0 个答案:

没有答案