mongodb(节点:37068)未处理的PromiseRejectionWarning:windows上的nodejs



我有这个错误:

(node:37068) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at NativeConnection.Connection.openUri (D:Downloadsnode-url-shortnernode_modulesmongooselibconnection.js:846:32)
at D:Downloadsnode-url-shortnernode_modulesmongooselibindex.js:350:10
at D:Downloadsnode-url-shortnernode_modulesmongooselibhelperspromiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (D:Downloadsnode-url-shortnernode_modulesmongooselibhelperspromiseOrCallback.js:30:10)
at Mongoose._promiseOrCallback (D:Downloadsnode-url-shortnernode_modulesmongooselibindex.js:1154:10)
at Mongoose.connect (D:Downloadsnode-url-shortnernode_modulesmongooselibindex.js:349:20)
at Object.<anonymous> (D:Downloadsnode-url-shortnerserver.js:5:10)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 (node:37068) 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:37068) [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:37068) UnhandledPromiseRejectionWarning: MongooseError: Operation `shorturls.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (D:Downloadsnode-url-shortnernode_modulesmongooselibdriversnode-mongodb-nativecollection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7) (node:37068) 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)

请帮帮我,我的node.js应用程序失败了

确保您的服务器已启动、正在运行并使用上述端口。您收到来自以下地址的拒绝连接错误:ECONNREFUSED 127.0.0.1:27017

如果你用try/catch块包装你的连接函数,效果会更好

最新更新