Not able to connect to mongodb cloud from node.js even though allowed anywhere network access

I have launched app using node.js.
Not able to connect to MongoDB cloud even though I allowed Connect from anywhere in the MongoDB network access.

Following error shows in the application

    "message": "Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist:",
    "reason": {
        "type": "ReplicaSetNoPrimary",
        "servers": {},
        "stale": false,
        "compatible": true,
        "heartbeatFrequencyMS": 10000,
        "localThresholdMS": 15,
        "setName": "Cluster0-shard-0",
        "maxElectionId": null,
        "maxSetVersion": null,
        "commonWireVersion": 0,
        "logicalSessionTimeoutMinutes": null

Hi @adminamigos,

I’m Dave, nice to meet you :slight_smile: - I’ll see if I can help you out!

Currently I’m not able to reproduce the issue on my side… here’s what I did:

  1. signed up for Mongo Atlas (free)
  2. ran through the onboarding stuff, using AWS as my database host. (note: i did it again with GCP)
  3. went to my network access section and added as the Access list entry (just clicked “Allow access from anywhere”, as you mentioned. Confirmed this and waited for status to be “active”
  4. Launched and Deployed a simple node application to fly based on this guide, without a database
  5. Once I got to the “A real database section” i stopped and ran npx node-demo --mongo in hopes that the project supported mongo (yessss it does!)
  6. opened my fly dashboard and added a secret DATABASE_URL with the connection string provided (described in the MongoDB quick start here)
  7. ran fly deploy on my terminal

This worked (for me) - The counter app increments, and a collection is visible in my Mongo Atlas collections explorer with an object that is incrementing when i refresh the fly app.

:thinking: At this point I do suspect a configuration issue or bug over on the Atlas side… A few suggestions/questions:

  • Can you provide any additional details of how your Atlas database is configured? It might be that I’m not capturing your use case here.
  • Does your app work with other cloud database providers?
  • Have you tried reaching out over on the mongodb side for support?

Hope this is helpful,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.