MongoDB DNS error

Hello, good afternoon.

I’m having one issue again with mongodb. Long story short it seems like replit DNS can’t resolve mongodb at all. I already checked it with them, but they said this is replit.com issue.

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 142)
e MongoServerSelectionError: getaddrinfo ENOTFOUND cluster0-shard-00-00.na0pa.mongodb.net
    at Timeout._onTimeout (/home/runner/depapier/node_modules/mongodb/lib/sdam/topology.js:330:38)
    at listOnTimeout (internal/timers.js:554:17) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map {
      'cluster0-shard-00-00.na0pa.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-01.na0pa.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02.na0pa.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-z66n3e-shard-0',
    logicalSessionTimeoutMinutes: undefined
  }
}

The issue is happening quite randomly nowadays. For example, my application was running just fine until a couple of hours ago. Then it stoped working and 2min ago it is back alive. Now it is dying again with the error above.

Yes, I’ve already contacted mongodb and they said it is an issue on replit side.

Can anyone help me?

Hey, @depapier welcome to the forums!

Can you please share a link to the repl?

https://replit.com/@MayssaLucena

the replit is called depapier

I dont see it. It may be private. Can you check the visibility of the repl?

Yes, it is private. I can’t make it public. It has private information

You should store private information using secrets to prevent people from being able to see it. It’s hard to help without being able to see what’s happening.

2 Likes

You could use secrets to hide that info!

2 Likes

I have the same problem, connecting to the MongoDB database.
MongooseServerSelectionError: 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: https://docs.atlas.mongodb.com/security-whitelist/

reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'cluster0-shard-00-00.ljoop.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-01.ljoop.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02.ljoop.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-jg73cd-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefine

I’m assuming you have checked your Atlas cluster’s IP whitelist?

Yes. I have all IPs unblocked (0.0.0.0)

Btw, I have another app running on a vps, with the same versions of node and mongoose, and the connection is performed perfectly. The problem is with Replit.

Hmm… that is odd. I’m afraid I have nothing to offer just based on that, not being experienced with MongoDB, but hopefully another member of the community will be able to help. :slight_smile:

1 Like

Oh, ok. Thanks anyway. <3

Does the following ip work?
34.149.204.188

This is the ip address of your site.

Yes. The whitelist is disabled. I’m enabling any IP to access my MongoDB.
Once again: The system is on and off randomly. This morning it was not working and after I waited 30min it went back on on its own.

It won’t work. replit is changing IPs every 24h or so.

I have worked with mongodb before on replit, let me check how did I do that if I still have that repl.

@Ethan by any change do you have any news on the matter?
It happened once again today 3h ago.

No. Since I dont know what your code looks like I don’t know what the problem is. I also do not work for Replit so I cant see stuff on the backend that could possibly be causing the problem if its not your code.

Thank you. I’ll wait for someone from replit to answer then. Like I said: it is not possible the use is related to my code. I’m not touching it but still the MongoDB connection comes and goes.
The only issue MongoDB support said is something related to DNS resolution.

does running kill 1 in shell fix it? If so, it’s probably something to do with a rate limit. You could do in a try-catch:

const { get } = require("https");
get("https://cd594a2f-0e9f-48f1-b3eb-e7f6e8665adf.id.repl.co/", () =>
  process.kill(1)
);

This restarts your repl to change the IP, then pings a website which then pings your repl back instantly to make your repl run.