Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡

I recently started looking into backend using the MERN stack, and sometimes it happens that I can’t connect to a Mongo cluster, even though it worked in the past. In 99% of the cases this is because my IP adress changed and my current IP is not whiteli…


This content originally appeared on DEV Community and was authored by Arika O

I recently started looking into backend using the MERN stack, and sometimes it happens that I can't connect to a Mongo cluster, even though it worked in the past. In 99% of the cases this is because my IP adress changed and my current IP is not whitelisted*. This is nothing that can't be fixed but I never remember what causes it and I waste time until I get to the correct solution (this is pretty much like forgetting how to center a div). When I would try to connect to a cluster I would see someting like this in the terminal (in the past I think I've also seen some straight up errors, but this is the most recent message I got):

[nodemon] 2.0.16
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
connection <monitor> to 52.58.6.203:27017 closed
[nodemon] clean exit - waiting for changes before restart

The connection couldn't be established because my IP address changed since I initially set up the cluster (or the last time I whitelisted my IP address). So what I would need to do is go to MongoDB Atlas and on the left side of the page, chose Security and then Network Access.

Image description

I would press ADD IP ADDRESS, wait for your current IP to be whitelisted and then try to reconnect. Now everything should work again. MongoDB is pretty good at auto detecting your current IP but if the connection still can't be established, try a quick "what's my ip" on Google and compare if the IP you got back is the same as the one detected by Mongo. If it's not, you might want to add it manually again.

*MongoDB Atlas only allows connections to clusters from IP addresses that are matched by entries in our project’s IP whitelist


This content originally appeared on DEV Community and was authored by Arika O


Print Share Comment Cite Upload Translate Updates
APA

Arika O | Sciencx (2022-07-03T16:51:48+00:00) Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡. Retrieved from https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/

MLA
" » Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡." Arika O | Sciencx - Sunday July 3, 2022, https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/
HARVARD
Arika O | Sciencx Sunday July 3, 2022 » Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡., viewed ,<https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/>
VANCOUVER
Arika O | Sciencx - » Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/
CHICAGO
" » Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡." Arika O | Sciencx - Accessed . https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/
IEEE
" » Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡." Arika O | Sciencx [Online]. Available: https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/. [Accessed: ]
rf:citation
» Remember to whitelist your IP when you can’t connect to Mongo DB 📡💡 | Arika O | Sciencx | https://www.scien.cx/2022/07/03/remember-to-whitelist-your-ip-when-you-cant-connect-to-mongo-db-%f0%9f%93%a1%f0%9f%92%a1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.