MongoDB atlas stopped working on replit (Python, pymongo)

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

1 Like

again, no experience with mongo but

import pymongo, os, multiprocessing
from pymongo import errors
from urllib import request
from http import server

# minimal server for if your code isn't already serving a website before you connect to mongodb
class Server(server.BaseHTTPRequestHandler):
    # Do this to override the log_request function to prevent spammy logging output
    def log_request(_, __):
        pass

    def do_HEAD(self):
        self.send_response(204)
        self.end_headers()

    do_GET = do_HEAD


multiprocessing.Process(
    target=server.ThreadingHTTPServer(("", 80), Server).serve_forever
).start()
try:
    # connect to mongo here, e.g.
    client = pymongo.MongoClient(
        f"mongodb+srv://admin:{os.environ['db-password']}@cluster0.1shpg.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
    )
except errors.ServerSelectionTimeoutError:
    request.urlopen(f"https://{os.environ['REPL_ID']}.id.repl.co")
    os.kill(1, 1)
1 Like

I’m now getting mongodb errors again (node.js), with Internal Server Error and Unknown system error -122. Looks like this issue wasn’t fully fixed and a timeframe on when this could be resolved would be great.

1 Like

Is there any update to this? Is it working again for anyone?

1 Like

No, it’s still a common error.

1 Like

This is really troublesome. It’s been 15 hours and I still can’t connect to MongoDB with replit.

1 Like

Yeah, very annoying.

1 Like

Yep really hurts my usability of Replit

1 Like

I don’t think it’s an issue on Replit’s side. I don’t know for certain, but my theory is that one of Replit’s IPs is blacklisted from Mongo as it’s only an issue sometimes and kill 1 sometimes helps.

1 Like

I apologize for our sparse updates! We are still coordinating with our upstream providers to find the cause. I have prompted the Replit team for an update and will revert here once I get a reply.

2 Likes

having the same issue, it’s been like this for since yesterday for me. Tried connecting to a different cluster and same issue

1 Like

Any update or solution for this issue?

Welcome comjoueur, @STCollier , @cheshire1, @ThiagoGlauco , @thedankboi , @MisterNoBot , @DooM , @WTV111 , and @1Tim to the ask forum! :wave: Everyone keeps forgetting to say welcome =\

This Problem is A deal Breaker The Server Is Unable To Connect To the Database And it’s causing a lot of down time (till now mostly down time) please an urgent fix is required

2 Likes

Mine just started being like it today. Any updates on the problem?

1 Like

We’re looking into this now that it has come up again, and we are able to reproduce it. We are getting in touch with an upstream service to coordinate the resolution of this issue.

2 Likes

Is there any temporary solution problem?

1 Like