I’m attempting to connect my Node.js application to my Cosmos DB for MongoDB but have been unsuccessful.
Connections are allowed from all networks in azure, however i can’t connect to my database directly from mongosh. I keep receiving the following error:
Connecting to: mongodb://<credentials>@mydb.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=%40jrfblogindb%40&directConnection=true MongoNetworkError: connect ECONNREFUSED 13.77.50.10:10255
I don’t believe the issue lies within my Node.js code as I’m receiving the same error as above. However, the error code from my Node.js application may provide some insight:
javascript
Failed to connect to database: MongoServerSelectionError: connect ECONNREFUSED 13.77.50.10:10255
at Topology.selectServer (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibsdamtopology.js:303:38)
at async Topology._connect (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibsdamtopology.js:196:28)
at async Topology.connect (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibsdamtopology.js:158:13)
at async topologyConnect (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibmongo_client.js:204:17)
at async MongoClient._connect (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibmongo_client.js:217:13)
at async MongoClient.connect (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibmongo_client.js:142:13) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(1) {
'jrfblogindb.mongo.cosmos.azure.com:10255' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'globaldb',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {},
[cause]: MongoNetworkError: connect ECONNREFUSED 13.77.50.10:10255
at connectionFailureError (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibcmapconnect.js:353:20)
at TLSSocket.<anonymous> (C:UsersJordanDownloadsWebsiteapinode_modulesmongodblibcmapconnect.js:268:44)
at Object.onceWrapper (node:events:635:26)
at TLSSocket.emit (node:events:520: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:82:21) {
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: Error: connect ECONNREFUSED 13.77.50.10:10255
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '13.77.50.10',
port: 10255
}
}
}
given that mongosh cant connect i take it isnt a node js issue, anyone with familiarity with azure cosmos that may have some troubleshooting would be appreciated.
I’ve attempted numerous methods, including deleting and recreating the database, disabling my firewall, confirming the connection script and re generating the connection script, reinstalling mongodb node module and mongosh.
Thanks!