I cannot connect to MongoDB Atlas database even though my IP is whitelisted - node.js

I am trying to connect to a mongoDB Atlas cluster using my node app, it wasn't working so I tried it with the mongoDB Compass. It shows timeout error. I can't figure out the problem, I have already whitelisted my IP from the database.
I am behind a proxy (my college has a proxy) but I even tried it with mobile data but it still won't work.

Related

Connect to MongoDB Atlas while i am behind college proxy

I have a MERN application in my system that used to work perfectly, now i am behind my college proxy , so I changed node proxy using
npm config set proxy http://username:password#host:port
npm config set https-proxy http://username:password#host:port
And in mongo atlas i have allowed all IP addresses to connect.
0.0.0.0/0 (includes your current IP address)
still while running the apllication i am getting this error from mongoDB side.
const serverSelectionError = new ServerSelectionError();
^
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/
I also tried to connect using mongosh and MongoDB compass any of these didn't connect to the atlas.
someone help me, please.

What does pataquets/mongodb-proxy this image exactly do? And how to configure this

Docker Pull Command: docker pull pataquets/mongodb-proxy
I am trying to figure out a way for connecting my nodejs backend to mongodb atlas, but through a proxy server.
This is because only the IP of the proxy server is whitelisted in mongoDB Atlas. I want to know if I can connect my backend to the mongodb atlas through the proxy server and I do not want to whitelist my nodejs server in mongodb atlas.
So trying to implement the same, I got this docker image, could anyone help me out with, does this image serve for this purpose, and what it is used for and how can I configure it.
As I could not find a detailed documentation, and I could not understand the documentation provided in the docker hub.
Thank you

Alternatives for connecting MongoDB Atlas to Heroku Node.js app

I've been working on a simple website using node.js, express, and MongoDB, with Heroku as the platform. I had a lot of issues early on trying to connect to my MongoDB Atlas cluster, resulting in Heroku throwing request timeout errors.
After some googling, I surmised that the issue was that the IP addresses Heroku sends requests to my DB from weren't whitelisted in Atlas. The simplest solution at that point was to egregiously set up so that any IP is considered whitelisted. Which actually works fine currently.
My actual question comes down to the fact that whitelisting all IPs hardly seems like a professional way to go about doing things.
What is a better solution?
You should only allow those IPs from which your application will connect to MongoDB Atlas. Allow all IPs is a bad practice and could make that MongoDB instance vulnerable.

Connect to MongoDB Atlas from Google App Engine

I'm trying to set up an API on the Google App Engine standard environment but I'm having trouble connecting to a distant MongoDB instance.
I use a free M0 cluster on MongoDB Atlas, all IP are whitelisted. The Google App Engine firewall rules allow all traffic from all IP addresses to make sure the connection request is not blocked.
However, I cannot connect to my Mongo instance and I get the following error:
ERROR db_connection querySrv ESERVFAIL <mongo-url>.gcp.mongodb.net
To connect to the MongoDB instance I use Mongoose and do the following:
const db = await mongoose.connect(uri, { useNewUrlParser: true });
However db will always be null since I cannot connect. Is there a way to connect to MongoDB Atlas from App Engine Standard or do I have to use Cloud Datastore ?
I had to use the older version of the atlas url
It works for me with older driver version url:
You don't have to use Datastore. You can connect to a mongoDB hosted outside of Google servers, there is some example code here. I would also like to refer you to this documentation on connecting to external databases from the Standard Environment.
Making sure your firewalls are open is necessary (and you have already done that, so that's great).
MongoDB Node.JS drivers are listed here, depending on the version you use, different reference documents are available with connection samples (all listed on that same link).

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Resources