2021.12.19报错解决:UnhandledPromiseRejectionWarning: MongoError: command find requires authentication

解决思路:

1.查看报错原因,翻译后了解原因

UnhandledPromiseRejectionWarning: MongoError: command find requires authentication

2.通过百度查询查看相似问题,通过博客:https://blog.csdn.net/w_hx10/article/details/109538770
知道是因为之前设置过mongodb的权限,所以访问时需要添加一些设置
3.按照博客进行修改,问题解决
总结:认真查看别人写的博客,要耐下性子去看别人的博客(之前看过几遍这个人的博客,但是忽视了这个博客)
完整报错代码:

PS E:\vscode\alibaixiu\code\alibaixiu> node .\app.js
(node:18100) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:18100) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:18100) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:18100) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
服务器启动成功
数据库连接成功
(node:18100) UnhandledPromiseRejectionWarning: MongoError: command find requires authentication
    at E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:581:63
    at authenticateStragglers (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:504:16)
    at Connection.messageHandler (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:540:5)
    at emitMessageHandler (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\connection.js:310:10)
    at Socket.<anonymous> (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\connection.js:453:17)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
(node:18100) 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:18100) [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.
(node:18100) UnhandledPromiseRejectionWarning: MongoError: command find requires authentication
    at E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:581:63
    at authenticateStragglers (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:504:16)
    at Connection.messageHandler (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\pool.js:540:5)
    at emitMessageHandler (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\connection.js:310:10)
    at Socket.<anonymous> (E:\vscode\alibaixiu\code\alibaixiu\node_modules\mongodb-core\lib\connection\connection.js:453:17)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
(node:18100) 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: 2)
上一篇:MongoDB应用案例:使用 MongoDB 存储商品分类信息


下一篇:Motorola XOOM平板电脑(wingray)刷机方法