首页 > 解决方案 > Mongo 错误:UnhandledPromiseRejectionWarning:MongoError:没有经过身份验证的用户

问题描述

为什么我会收到此错误。我在使用 macbook pro。在一个项目中工作,该项目有一个 node.js api 和 mongodb 数据库,其中 mongoose 作为 ODM 和一个快速服务器。我多次看到这个错误,不知道为什么会这样。有人有想法吗?希望得到一些帮助。

我试过的:卸载Mongodb,重新安装。擦除项目文件并重新克隆它们。擦拭我的 Mac(这有效,但当再次出现此错误时必须再次执行此操作)。也没有任何身份验证,所以它不应该要求它。

我还检查并确保我的代码没有未处理的承诺,我已经确认。

MongoDB connected
listening on http://localhost:4000
(node:57471) UnhandledPromiseRejectionWarning: MongoError: there are no users authenticated
    at Connection.<anonymous> (/Users/chirag/Desktop/labs/shopping-cart-be/node_modules/mongodb/lib/core/connection/pool.js:460:61)
    at Connection.emit (events.js:315:20)
    at processMessage (/Users/chirag/Desktop/labs/shopping-cart-be/node_modules/mongodb/lib/core/connection/connection.js:368:10)
    at Socket.<anonymous> (/Users/chirag/Desktop/labs/shopping-cart-be/node_modules/mongodb/lib/core/connection/connection.js:537:15)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
(node:57471) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:57471) [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.

标签: javascriptnode.jsmongodb

解决方案


推荐阅读