Unable to connect to Cosmos DB for mongoDB

Jordan Casson-Jones 0 Reputation points
2024-08-14T14:29:51.67+00:00

Greetings,

I'm attempting to connect my Node.js application to my Cosmos DB for MongoDB but have been unsuccessful. I've attempted numerous methods, including deleting and recreating the database. Connections are allowed from all networks, but 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=%40mydb%40&directConnection=true MongoNetworkError: connect ECONNREFUSED dbIP: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 dbIP:10255
    at Topology.selectServer (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\sdam\topology.js:303:38)
    at async Topology._connect (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\sdam\topology.js:196:28)
    at async Topology.connect (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\sdam\topology.js:158:13)
    at async topologyConnect (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\mongo_client.js:204:17)
    at async MongoClient._connect (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\mongo_client.js:217:13)
    at async MongoClient.connect (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\mongo_client.js:142:13) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(1) {
      'mydb.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 dbip:10255
      at connectionFailureError (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\cmap\connect.js:353:20)
      at TLSSocket.<anonymous> (C:\Users\Jordan\Downloads\Website\api\node_modules\mongodb\lib\cmap\connect.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 dbip:10255
        at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
      errno: -4078,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: 'dbip',
      port: 10255
    }
  }
}

I've disabled my firewall to ensure that it's not blocking my connection, but I still can't access my database. Can anyone offer some advice on how to troubleshoot this issue?

Thank you kindly.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,642 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. TP 95,866 Reputation points
    2024-08-14T15:21:17.8166667+00:00

    Hi Jordan,

    As a test I just created new database, downloaded mongosh, and pasted the connection string and it worked fine. Below is screenshot with private info redacted:qna mongosh test

    Have you tried creating the database in a different region? Have you tried connecting from a different PC and/or Internet connection? Perhaps if you provide more details I can try to recreate the issue.

    -TP


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.