Mongo运行异常:Failed to connect 127.0.0.1:27017,reason:errno:10061

解决MongoDB连接失败问题
本文介绍了当遇到MongoDB连接失败错误时的解决方法。主要原因是mongodb服务未启动,通过命令mongod --dbpath d:mongodbdata 开启服务即可解决。此外还提供了在Windows环境下将mongodb设置为服务的具体步骤。

 

 

Mongo运行错误:Failed to connect 127.0.0.1:27017,reason:errno:10061

Mongo运行错误:Failed to connect 127.0.0.1:27017,reason:errno:10061由于目标计算机积极拒绝,无法连接

Mongo运行错误:如下

原因是mongodb的服务没有开启,开启服务后问题就能解决了,开启服务命令:mongod --dbpath "d:\mongodb\data

只要操作mongodb数据库,服务就要一直开着

使用管理员权限打开windows的cmd窗口,进入D:\dev\mongodb-win32-x86_64-2.4.5\bin目录。
mongod.exe --install --logpath=D:\dev\mongodb-win32-x86_64-2.4.5\log\log.txt --dbpath=D:\dev\mongodb-win32-x86_64-2.4.5\data\db
--install 参数是设定安装为服务器

设置为服务后,即可在cmd 输入services.msc(管理员权限打开的windows cmd窗口)窗口用服务的方式启动或停止MongoDB。
net start mongodb 启动mongodb服务
net stop mongodb 启动mongodb服务

转载于:https://my.oschina.net/fymoon/blog/754804

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值