ReplicaSetNoPrimary error after a while


We are using MongoDB payed version and we started receiving ReplicaSetNoPrimary error randomly this week on local. We are using node.js but when the error appears while we are working, it´s stop answering from Atlas too.

  1. Our ip is allowed
  2. Our local firewall is disabled
  3. Is working in production and the URL string is the same
  4. It happens only sometimes and when it’s about to happen the queries start working really slow
  5. When it happens it stops working from MongoDB Compass too and we are using +srv URL

Any advice is appreciated. Thank you

This is the error we receive from mongoose

MongoServerSelectionError: connect ECONNREFUSED SERVER_IP:27017
     at Timeout._onTimeout (/home/node/app/node_modules/mongodb/lib/sdam/topology.js:318:38)
     at listOnTimeout (internal/timers.js:554:17)
     at processTimers (internal/timers.js:497:7) {
   reason: TopologyDescription {
     type: 'ReplicaSetNoPrimary',
     servers: Map(3) {
       '*****' => [ServerDescription],
       '*****' => [ServerDescription],
       '*****' => [ServerDescription]
     stale: false,
     compatible: true,
     heartbeatFrequencyMS: 10000,
     localThresholdMS: 15,
     setName: 'atlas-*****-shard-0',
     logicalSessionTimeoutMinutes: undefined
   code: undefined,
   [Symbol(errorLabels)]: Set(0) {}

Hi @dimitar_vasilev and welcome to the MongoDB community forum!!

Thank you for sharing the above information in detail. However, to understand clearly, could you help with a few more details below:

  1. Could you clarify if you are using a paid tier MongoDB Atlas instance or are you referring to an on-prem self-hosted enterprise deployment here?
  1. Could you help with the node version you are using?
  1. Can you help me understand if this was seen throughout the time the connection is build or is seen randomly. Was there something changed on the application end when the issue started to occur.
  1. If you are on the Atlas deployment, could you confirm if you are observing something notable change on the metrics end? Please review the following How to Monitor MongoDB page which could possibly assist you with this.

Please let me know if you have any further queries.

Best Regards

Hi Assawari thank you for your answer.

  1. We are using MongoDB Atlas instance
  2. Node v16.1.0
  3. It’s actually randomly, it can happent while the connection is beign made or after. The interesting is that it happens only on local dev environment.
  4. I tried monitoring the problem many times but nothing I coudn’t see anything important. All seems to be fine. And is working on production which uses the exact same connection string.

Let me know if there is anything I can provide to help understand the problem better.

Thank you for your time!

Hi @dimitar_vasilev and thank you for your reply.

It would be helpful if you help me understand further with more details.

Does this mean that only the local MongoDB you’re having issues with but not Atlas?
Could you confirm how the local environment was run? Is it on a laptop, what’s the mongod command line parameters are?
What are the operating system configuration?

Could you also provide the connection string that you are using to connect for both the environments?

Does you local setup has a different configuration or security setting from the the production environment ?