首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017

UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
EN

Stack Overflow用户
提问于 2020-08-31 21:40:47
回答 8查看 18K关注 0票数 3

我下载了mongoDB,它工作得很好,但是当我想使用REST API并在命令行中使用npm run dev时,它给了我这个错误。That's an error

代码语言:javascript
复制
(node:10100) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (D:\Node Js\task-manager\node_modules\mongoose\lib\connection.js:800:32)
    at D:\Node Js\task-manager\node_modules\mongoose\lib\index.js:341:10
    at D:\Node Js\task-manager\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
    at new Promise (<anonymous>)
    at promiseOrCallback (D:\Node Js\task-manager\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
    at Mongoose.connect (D:\Node Js\task-manager\node_modules\mongoose\lib\index.js:340:10)
    at Object.<anonymous> (D:\Node Js\task-manager\src\db\mongoose.js:3:10)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (D:\Node Js\task-manager\src\index.js:2:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
(node:10100) 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:10100) [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.

在此之前,当我想连接数据库并投影它时,它可以工作,但现在它不工作,当我尝试连接它时,它正在停止And thats not connecting picture

EN

回答 8

Stack Overflow用户

发布于 2020-12-28 02:50:24

考虑到在发出npm run dev之前MongoDB应该处于运行状态。

您必须先使用mongod命令初始化数据库引擎。有时很容易忘记这一步。

票数 3
EN

Stack Overflow用户

发布于 2020-08-31 22:18:52

我认为您的URL格式不正确,

使用下面的URL

代码语言:javascript
复制
mongodb://localhost:27017/{DATABASE_NAME}
票数 2
EN

Stack Overflow用户

发布于 2021-11-23 10:10:20

在我的示例中,当我将"mongodb://localhost:27017“更改为"mongodb://127.0.0.1:27017”时,它起作用了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63671934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档