Connection refused ( Error: connect ECONNREFUSED ::1:27017 )

Hello Team,

We have started the mongodb services with this command (mongod --dbpath path…)

Please find below error logs for issue while uploading data through mongodb, Please help.
Connection fails: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkTimeoutError: connection timed out
at connectionFailureError (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:362:14)
at Socket. (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:330:16)
at Object.onceWrapper (node:events:627:28)
at Socket.emit (node:events:513:28)
at Socket._onTimeout (node:net:568:8)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)]
It will be retried for the next request.
[2023-02-09T05:21:04.908Z] ERROR: oe-logger on DESKTOP-TP7LI63: (boot-db-models, system)
modelDefinition.findOne name=" User " Error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
name: ‘MongoNetworkError’
}]
at Pool. (D:\SpeedUp\node_modules\mongodb\lib\core\topologies\server.js:441:11)
at Pool.emit (node:events:513:28)
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\pool.js:564:14
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\pool.js:1000:11
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:32:7
at callback (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:300:5)
at Socket. (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:330:7)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
(node:852) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 17 connected listeners added to [DataSource]. Use emitter.setMaxListeners() to increase limit
(node:852) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 17 error listeners added to [DataSource]. Use emitter.setMaxListeners() to increase limit
Unhandled rejection MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
name: ‘MongoNetworkError’
}]
at Pool. (D:\SpeedUp\node_modules\mongodb\lib\core\topologies\server.js:441:11)
at Pool.emit (node:events:513:28)
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\pool.js:564:14
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\pool.js:1000:11
at D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:32:7
at callback (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:300:5)
at Socket. (D:\SpeedUp\node_modules\mongodb\lib\core\connection\connect.js:330:7)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

We have tried every solution given on community forum.
mongodb version : 5.0.14
OS : windows 10

Any help would be greatly appreciated.

If your mongod is already running as Windows service there is no need to start another mongod
Check whether you can connect by shell and investigate why it is failing with your app

Thanks :slight_smile: Ramachandra sir for your assistance,
We have tried in shell and tried with every possible thing still no luck, but it is working fine in mac.
It would be greatly appreciated if you could extend your help a little bit.

Normally you get connection refused if no process is actively listening on that port.
So make sure the mongodb process is indeed listening on local:27017.

You can use something like netstat to verify that.

1 Like

Show us output of mongo/mongosh (depending on your mongodb version) from Windows command prompt as screenshot

Thanks, Ramachandra
Please find attached screenshots.

image

I don’t see any issue
In your first snapshot you are connected to mongodb
Just run some commands like
db
Show dbs
The command you ran in second snapshot is not correct
Either you should use mongo or mongosh depending on what is installed/available on your machine

Hello Team,

Many thanks for you support :slight_smile:
Issue resolved by replacing node version with v16.14.2

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.