mongodb 问题 failed to connect to server [127.0.0.1:27017] on first connect

UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

错误

在这里插入图片描述

可考虑以下两种原因

1、没有安装 mongodb
2、已安装 mongodb ,但没有启动 mongodb 服务器

解决

  • 安装 mongodb
  • 启动服务器(参考安装和配置链接
    通过控制台进入 mongodb 的安装目录,找到 bin 文件夹下面的 mongod.exe 并执行
MongoDB 连接错误: MongoServerSelectionError: connect ECONNREFUSED 180.184.39.232:48354 at Topology.selectServer (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\sdam\topology.js:321:38) at runNextTicks (node:internal/process/task_queues:65:5) at listOnTimeout (node:internal/timers:555:9) at process.processTimers (node:internal/timers:529:7) at async Topology._connect (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\sdam\topology.js:200:28) at async Topology.connect (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\sdam\topology.js:152:13) at async topologyConnect (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\mongo_client.js:233:17) at async MongoClient._connect (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\mongo_client.js:246:13) at async MongoClient.connect (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\mongo_client.js:171:13) at async NativeConnection.createClient (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongoose\lib\drivers\node-mongodb-native\connection.js:351:3) { errorLabelSet: Set(0) {}, reason: TopologyDescription { type: 'Single', servers: Map(1) { 'dbconn.sealosbja.site:48354' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined, [cause]: MongoNetworkError: connect ECONNREFUSED 180.184.39.232:48354 at Socket.<anonymous> (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\cmap\connect.js:285:44) at Object.onceWrapper (node:events:633:26) at Socket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) { errorLabelSet: Set(1) { 'ResetPool' }, beforeHandshake: false, [cause]: Error: connect ECONNREFUSED 180.184.39.232:48354 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1634:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '180.184.39.232', port: 48354 } } } D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongoose\lib\connection.js:1165 err = new ServerSelectionError(); ^ MongooseServerSelectionError: connect ECONNREFUSED 180.184.39.232:48354 at _handleConnectionErrors (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongoose\lib\connection.js:1165:11) at NativeConnection.openUri (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongoose\lib\connection.js:1096:11) at runNextTicks (node:internal/process/task_queues:65:5) at listOnTimeout (node:internal/timers:555:9) at process.processTimers (node:internal/timers:529:7) { errorLabelSet: Set(0) {}, reason: TopologyDescription { type: 'Single', servers: Map(1) { 'dbconn.sealosbja.site:48354' => ServerDescription { address: 'dbconn.sealosbja.site:48354', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, minRoundTripTime: 0, lastUpdateTime: 144818976, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED 180.184.39.232:48354 at Socket.<anonymous> (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\cmap\connect.js:285:44) at Object.onceWrapper (node:events:633:26) at Socket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) { errorLabelSet: Set(1) { 'ResetPool' }, beforeHandshake: false, [cause]: Error: connect ECONNREFUSED 180.184.39.232:48354 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1634:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '180.184.39.232', port: 48354 } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, maxMessageSizeBytes: null, maxWriteBatchSize: null, maxBsonObjectSize: null, primary: null, me: null, '$clusterTime': null, iscryptd: false } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined, cause: TopologyDescription { type: 'Single', servers: Map(1) { 'dbconn.sealosbja.site:48354' => ServerDescription { address: 'dbconn.sealosbja.site:48354', type: 'Unknown', hosts: [], passives: [], arbiters: [], tags: {}, minWireVersion: 0, maxWireVersion: 0, roundTripTime: -1, minRoundTripTime: 0, lastUpdateTime: 144818976, lastWriteDate: 0, error: MongoNetworkError: connect ECONNREFUSED 180.184.39.232:48354 at Socket.<anonymous> (D:\ExpressLearning\express-locallibrary-tutorial\node_modules\mongodb\lib\cmap\connect.js:285:44) at Object.onceWrapper (node:events:633:26) at Socket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) { errorLabelSet: Set(1) { 'ResetPool' }, beforeHandshake: false, [cause]: Error: connect ECONNREFUSED 180.184.39.232:48354 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1634:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '180.184.39.232', port: 48354 } }, topologyVersion: null, setName: null, setVersion: null, electionId: null, logicalSessionTimeoutMinutes: null, maxMessageSizeBytes: null, maxWriteBatchSize: null, maxBsonObjectSize: null, primary: null, me: null, '$clusterTime': null, iscryptd: false } }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null } } Node.js v22.14.0
06-03
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值