node.js - 未处理的 promise 拒绝警告 : MongooseServerSelectionError: connect ECONNREFUSED 127. 0.0.1:27017

标签 node.js mongodb localhost

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

(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

最佳答案

在发出 npm run dev 之前考虑到 MongoDB 应该正在运行。

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

关于node.js - 未处理的 promise 拒绝警告 : MongooseServerSelectionError: connect ECONNREFUSED 127. 0.0.1:27017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63671934/

相关文章:

javascript - Backbone.js 应用程序使用 CommonJS 结构与 node.js 和客户端一起工作

mongodb - 如何使用GoLang在MongoDB中执行插入操作?

node.js - 如何解决 `TypeError: person.save is not a function` - 出了什么问题?

javascript - 无法删除(设置为过期)本地主机上的 cookie

javascript - 切换 Node.js 应用程序时 localhost:3000 不会改变

node.js - 无法使用 firebase 函数将字节数组图像上传到 fire-storage

javascript - 使分页与其计数一起工作

node.js - 重定向到 express.js 中的静态文件

java - 外部对象引用/多对象提交

node.js - WebSocket 安全本地主机连接