skip to Main Content

const timeoutError = new error_1.MongoServerSelectionError(Server selection timed out after ${serverSelectionTimeoutMS} ms, this.description);
MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (C:Users*DesktopMONGODBNEW SERVERnode_modulesmongodblibsdamtopology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: ‘Unknown’,
servers: Map(1) {
‘localhost:27017’ => ServerDescription {
address: ‘localhost:27017’,
type: ‘Unknown’,
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 491601161,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:Users*
DesktopMONGODBNEW SERVERnode_modulesmongodblibcmapconnect.js:370:20)
at Socket. (C:UsersANMOLDesktopMONGODBNEW SERVERnode_modulesmongodblibcmapconnect.js:293:22)
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) {
cause: Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -4078,
code: ‘ECONNREFUSED’,
syscall: ‘connect’,
address: ‘::1’,
port: 27017
},
[Symbol(errorLabels)]: Set(1) { ‘ResetPool’ }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
‘$clusterTime’: null
}
},

I ran mongod in one terminal and node in other but some connectivity error is showing

2

Answers


  1. MongoDB might running at a different address or port: This means that the MongoDB service is not running at the default address (localhost or 127.0.0.1) and port (27017). It might be that when you installed MongoDB or when you are running it, you specified a different address or port number.
    To resolve this:

    Check where MongoDB is running: First, we need to check whether MongoDB is running and on which port. You can find this in the output when you start mongod in the terminal. Typically, it prints a message like:

    [initandlisten] waiting for connections on port <port>
    

    Where is the port number MongoDB is listening on.

    If MongoDB is running on a different port, you should see that port number instead of 27017.

    Update your connection string: Once you have confirmed the address and port where MongoDB is running, you need to use those in your connection string in your Node.js code.

    If for example, MongoDB is running on port 27018 on your localhost, then in your Node.js code where you establish a connection with MongoDB using the MongoDB Node.js driver, you need to update your connection string to reflect this.

    So, if your original connection string was something like:

    const url = 'mongodb://localhost:27017';
    

    You’d change it to:

    const url = 'mongodb://localhost:27018';
    

    Related Issues
    MongoServerSelectionError: connect ECONNREFUSED ::1:27017

    Login or Signup to reply.
  2. This answer from the mongodb community worked for me: https://www.mongodb.com/community/forums/t/econnrefused-27017/131911/6

    I changed the localhost to

    const uri = ‘mongodb://127.0.0.1:27017’;

    Initially this is what I had:

    mongodb://localhost:27017/

    I hope my answer helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search