MongoDB atlas stopped working on replit (Python, pymongo)

It looks like MongoDB atlas stopped working on replit. My code:

def connect_to_db():
    return pymongo.MongoClient(
        f"mongodb+srv://admin:{os.environ['db-password']}@cluster0.1shpg.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
    )

subprocess.call(['pip', "install", "pymongo[srv]==3.12"])
import pymongo

client = connect_to_db()
collection = client["projects"]["all"]
collection.insert_one({"test":"test"})

The code used to work until ~7 days ago (and it still works on my computer), but now I’m getting this error on replit:

[...]
pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-01.1shpg.mongodb.net:27017: [Errno -3] Temporary failure in name resolution,cluster0-shard-00-02.1shpg.mongodb.net:27017: [...]

I already tried it with another mongodb project, same error. Anyone who knows how to fix it?

5 Likes

Hi @1Tim I’m going to move this to Bug Report as this isn’t something the community can reproduce (as we don’t have access to your secrets).

If you can provide a link to the Repl it would be much appreciated.

2 Likes

Hey, I have the same problem. Everything is crashing since yesterday. I’m a PRO member and I’m paying specifically for this. Please fix it, it’s urgent.

1 Like

pymongo.errors.ServerSelectionTimeoutError: ac-ksoins6-shard-00-00.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution,ac-ksoins6-shard-00-01.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution,ac-ksoins6-shard-00-02.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution, Timeout: 30s, Topology Description: <TopologyDescription id: 6385464473257e5b3c7ec593, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-ksoins6-shard-00-00.iqocfeo.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ksoins6-shard-00-00.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution')>, <ServerDescription ('ac-ksoins6-shard-00-01.iqocfeo.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ksoins6-shard-00-01.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution')>, <ServerDescription ('ac-ksoins6-shard-00-02.iqocfeo.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ksoins6-shard-00-02.iqocfeo.mongodb.net:27017: [Errno -3] Temporary failure in name resolution')>]>

2 Likes

Same problem in hackerplan. But works perfectly in free plan.

Then, What is the benefit of Pro member?!

Fix it please.
Link to my repl: https://replit.com/@NafisAfzal2017/Mongo-Test

1 Like

i have the same problem, is this bug is going to be fixed or what? if yes, please fix it ASAP, im begging…

FIXED!

My repls are running as okay! :")

Thanks replit team. <3

2 Likes

Great to hear @NafisAfzal2017!

We’re working on a fix!

1 Like

Replit staff member ^^. So that may be the fix

2 Likes

@not-ethan that’s not the fix :slight_smile: we’re working on a fix for the Mongo not connecting issue

4 Likes

Bardia, it worked for 48 hours and broke again this morning. What’s going on! :smiling_face_with_tear:

When can we expect a fix?

We have our engineering team working on it right now. Hopefully by the end of the week, maybe next week. Sorry for the disruption to our services!

3 Likes

Same here, it didn’t work, then worked for a while, and now doesn’t work.

I have a fix that works for me. I imported dns and my problems were resolved

import os
import dns
os.system("python -m pip install \"pymongo[srv]\"")
import pymongo
1 Like

Update: We are still digging into this issue

2 Likes

I’m also having Server selection error using Node.js. I think is something related to name resolution in the container.

I don’t do mongo, but see if this code works around the issue. It’s meant to switch the IP when the error happens

const { MongoClient, MongooseServerSelectionError } = require("mongodb");
// minimal webserver if you don't already serve a website
require("http")
  .createServer((_, r) => r.end())
  .listen();
try {
  // whatever code you use to connect, like
  await new MongoClient(yourConnectionURI).connect();
} catch (err) {
  if (err instanceof MongooseServerSelectionError) {
    require("https").get(`https://${process.env.REPL_ID}.id.repl.co`, () =>
      process.kill(1)
    );
  }
}

This exact error randomly showed up on my repl today after no changes and having worked flawlessly for months.

Is there a solution for this? Python with PyMongo?

Thanks!

Yep started again for me too yesterday