MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 不会被修复
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 不会被修复
我已经尝试了超过2个小时,试图弄清楚这个数据库出了什么问题。我尝试了一切办法,从重新安装服务器,重启进程,重启等等。在尝试连接时,它一直给我这个错误:
const serverSelectionError = new ServerSelectionError(); ^ MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at NativeConnection.Connection.openUri (D:\TheShed\MX_\node_modules\mongoose\lib\connection.js:797:32) at D:\TheShed\MX_\node_modules\mongoose\lib\index.js:330:10 at D:\TheShed\MX_\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5 at new Promise () at promiseOrCallback (D:\TheShed\MX_\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (D:\TheShed\MX_\node_modules\mongoose\lib\index.js:1151:10) at Mongoose.connect (D:\TheShed\MX_\node_modules\mongoose\lib\index.js:329:20) at module.exports (D:\TheShed\MX_\other\DB\mong.js:4:20) at D:\TheShed\MX_\app.js:195:37 at Object. (D:\TheShed\MX_\app.js:197:3) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => ServerDescription { _hostAddress: HostAddress { isIPv6: false, host: 'localhost', port: 27017 }, address: 'localhost:27017', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, lastUpdateTime: 1421094, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED ::1:27017 at connectionFailureError (D:\TheShed\MX_\node_modules\mongodb\lib\cmap\connect.js:293:20) at Socket. (D:\TheShed\MX_\node_modules\mongodb\lib\cmap\connect.js:267:22) at Object.onceWrapper (node:events:510:26) at Socket.emit (node:events:390:28) at emitErrorNT (node:internal/streams/destroy:164:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, logicalSessionTimeoutMinutes: undefined } }
无论我做什么,这个错误都无法解决。MongoDB服务器正在运行,我通过>show dbs来检查,它们都显示正常。而且,C:/data/db也存在且正常。
我该怎么办?
这是我的连接代码:
(async () => { await require('./other/DB/mong')(); console.log("已连接到数据库。"); })();
这是 ./other/DB/mong 的代码:
var mongoose = require("mongoose"); module.exports = async () => { await mongoose.connect('mongodb://localhost:27017/MX', { keepAlive: true, useNewUrlParser: true, useUnifiedTopology: true }); return mongoose; }