I keep getting this error although I have allowed access from anywhere in the Network access section of the cluster. (Screenshot of the same is attached below)
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/
at NativeConnection.Connection.openUri (/home/runner/store-cipher-backend-1/node_modules/mongoose/lib/connection.js:824:32)
at /home/runner/store-cipher-backend-1/node_modules/mongoose/lib/index.js:380:10
at /home/runner/store-cipher-backend-1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/home/runner/store-cipher-backend-1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/home/runner/store-cipher-backend-1/node_modules/mongoose/lib/index.js:1225:10)
at Mongoose.connect (/home/runner/store-cipher-backend-1/node_modules/mongoose/lib/index.js:379:20)
at intialDbConnection (/home/runner/store-cipher-backend-1/db/db.connect.js:5:20)
at Object.<anonymous> (/home/runner/store-cipher-backend-1/index.js:15:1) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'cluster0-shard-00-00.fkvic.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-01.fkvic.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-02.fkvic.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-on2j4f-shard-0',
logicalSessionTimeoutMinutes: undefined
},
code: undefined
}
did you do this from replit console or your pc? where do you run your app? replit, work pc or home pc?
I have tried and replit has no problem connecting Atlas clusters.
One possibility is that you just haven’t waited long enough when you added “0.0.0.0” to your network list. for me, it took about 15-20 seconds for the change to take effect.
Yes, It’s a free repl, and yes it stops but once I restart the server, The server gets connected successfully and the MongoDB error raises. (DB doesn’t connect)
The port test succeeds but the error isn’t resolved. The port test is always successful.
Today, I could finally get the same problem you are experiencing.
Then, I did a side-by-side test with replit and Compass. Removing and re-adding the access from everywhere. Compass had no problem connecting.
It seems the problem arises from the container (virtual machine) our repl is started. I got two different addressses that both succeeded portquiz.net test but one failed to connect mongodb:
23.251.145.77 → Failed
35.203.153.221 → Connected
I have sent a bug report within the repl. I can’t say what happens next. I suggest you close/reopen the repl by going back to “My Repls” page, waiting a bit, and re-open it. check if you connect. if not, try again.
Struggling for 2 days with the same connection issue. Tried suggested test methods and all of them are passed however still receiving error from mongodb.
Waiting for a solution impatiently (my certification got stuck halfway).
Hi @Valikhan_Dumshebayev, Although the error is generic, the problem here turned out to be related to replit.com container. If your case is also related to a repl, please read my post just above yours. Else read on.
The root of the problem is the strict access rules on the host network your app runs. You might be behind a strict school/work network that prevents certain connections to the internet. In these cases, you need to move to a more permissive network such as home or mobile.
PS: It is still a mystery to me why we can connect to portquiz.net but not to mongodb servers.
I am on my home network with no restriction. Actually, for me it has started at Saturday, then all of a sudden it got connected on Monday for some time and get disconnected again. Didn’t check on Sunday, though.
Can you please make a new post, include the full error message you get, and include a link here (because of irregularities)? That will allow both us community helpers and the mongodb staff to look with fresh sight.
I know it is a pain to get a working container just continue with your luck.
Please also consider sending a bug report from within the repl (help button on bottom-left) about this problem so to make replit team aware of the situation.
If you are following this thread, here is the temporary solution provided by replit support team.
“You can run “kill 1” in the shell of your Repl which will reboot it and may fix the issue, although it isn’t a 100% reliable workaround.”
Apart from this the solution that has worked for me is changing the file name and running, the DB gets connected. In case you have already used the APIs in the frontend, after doing the above step change back your file name to the old one and the DB gets connected without any issues.