Suddenly can't connect to DB for apparently no reason at all

Hi MongoDB community!

Everything has been running smoothly until 2 days ago. Yesterday, I resume my cluster and notice that my data isn’t showing up on my site in localhost. I was getting 500 internal server errors in my dev environment ONLY (localhost:3000). My site in production was working just fine. I tried debugging all day with atlas basic tech support, but to no avail. I pause the cluster after trying to fix the issue all day. Today, I resume the cluster then go to my prod site and was shocked to see no data. Also getting 500 errors. So, now I can’t connect to MongoDB at all! Both dev and prod environments can’t connect to my MongoDB Atlas cluster. I can’t connect to my cluster via Compass either even though I never used it until now for debugging purposes. What’s super weird is that there is literally no reason for my prod site to lose connection to the DB because I haven’t pushed or deployed any code to Vercel or Github in the last 35 days. I host my Next js headless Ecommerce app on Vercel. I recently integrated Vercel with MongoDB, yet it was working for a whole year without that integration. I thought the integration would at least fix the issue in Prod, but it didn’t. My IP address in Network Access is set to 0.0.0.0. I also updated my password in Database Access, but that didn’t do anything either. I don’t have any VPNs or Firewalls enabled on my Mac. I also tried on PC and on a different Mac.

In localhost:3000, when I start up my app, I get the 500 error in my console log in about 20-30 seconds. So, I guess it’s trying to connect then it just times out. In my VSCode terminal, I get this error at the same time:

error - unhandledRejection: MongoServerSelectionError: connect ECONNREFUSED 52.87.112.56:27017
at Timeout._onTimeout (/Users/davidmedero/Desktop/nextjs-shopify-tailwind-1/node_modules/mongodb/lib/sdam/topology.js:277:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'cluster0-shard-00-02.axvkp.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-00.axvkp.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-01.axvkp.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-z81cvx-shard-0',
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}

I would really appreciate your help on this one guys. I’m at a loss.

Never mind, I fixed it. I had to delete my node modules and package-lock.json then npm install. I was using Bun prior, but I noticed it was installing different versions of my dependencies.

1 Like

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