Getting MongoServerSelectionError: Server selection timed out after 30000ms from localhost:5173

Bharath 0 Reputation points
2023-02-16T14:56:09.3566667+00:00

Hi All

I have a mongodb database wrapped inside Azure CosmosDB, I am using a node.js v16.17.1 application using the backend as azure CosmosDB. This application is deployed as a ContainerApp in Azure, there it is working fine while connecting to cosmos-db.

When I connect through localhost:5173:
It was working fine, but suddenly i am getting the below error from a particular day.


MongoServerSelectionError: Server selection timed out after 30000 ms
    at Timeout._onTimeout (node_modules/mongodb/lib/sdam/topology.js:291:38)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(1) {
      'my-db.mongo.cosmos.azure.com:10255' => ServerDescription {
        address: my-db.mongo.cosmos.azure.com:10255',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 7381815,
        lastWriteDate: 0,
        error: null,
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
      }
    },

There are no permissions or network issue as I have allowed public network access to the db instance and it was always working.

even from mongsh <connectionstring> i am getting the same error.

Connection : is through my home wifi network which uses wpa2 personal. Before sometime back i was using wpa security. I am using a mac . My organization disallowed wpa security so i switched to wpa2 and ever since i notice this error when connecting from my localhost with my wifi network

ConnectionString:
mongodb://my-db-:abcdefghijklmnopqrst==@my-db.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@my-db@

Mobile hotspot:
Able to connect with my mobile-hotspot in the same machine to the same remote db without any errors. both with the mongosh as well as nodejs app

Any inputs here? Thanks

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,901 questions
{count} votes

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.