Connect to MongoDB Atlas while i am behind college proxy - node.js

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.

Related

Connecting to Mongodb without Auth?

I have Mongodb installed on my Ubuntu server. I allowed the server IP in the database config file. Port 27017 is open. The auth is off on the database meaning everybody is supposed to be able to connect to it via this URI string using Compass:
mongodb://<server IP address>:27017
with all this conditions ongoing, I still cannot connect to db with this URI string. Why?

Dockerized MongoDB Replica Set Access Outside Container

Short Description of the Setup
I have a one-member replica set (why? see bottom). The mongo service is running inside a docker container. In the replica set config each member is referenced by a hostname, since I am using a docker container I am using its name (mongodb0) as hostname. The mongodb port is forwarded to the host machine.
Problem
For debugging purposes I would like to access the db from outside the container. Just using mongosh works, although it seems it is not recognizing the instance as part of the replica set. Connecting a node driver to mongodb0 does not work at all (to be expected, since the hostname is only resolved inside the container) however, I would think I can connect to localhost:27017 which is the forwarded port (that's why mongosh is working) but it's throwing following error:
MongoServerSelectionError: getaddrinfo ENOTFOUND mongodb0
...
Note I am using localhost in my node driver connection string.
Why am I using a replica set with only one member? Only a replica sets allows me to use the change streams.

Heroku and MongoDB atlas connection

I use Heroku as a server and I use MongoDB Atlas as a database. But since Heroku does not have an IP address, I cannot connect to MongoDB via Heroku. It is said to make the IP address 0.0.0.0 as a platform solution. But MongoDB Atlas no longer accepts this ip address. What solution can I find for this? Thanks for your help in advance.
enter image description here
Actually, MongoDB Atlas supports the IP Address that you are talking about (0.0.0.0).
However, you have a small mistake in your configuration, it should be 0.0.0.0/0 (with the subnet mask).
To configure this, just go to your MongoDB Atlas, click Network Access (in the left sidebar as of the time of this answer was written), then add the IP address of 0.0.0.0/0. There should also be a setting to Allow Access From Anywhere. You can click it and the result will also be the 0.0.0.0/0 IP address.
Save then wait for MongoDB Atlas to process it. Then, simply connect to your database as usual with the connection string.

I cannot connect to MongoDB Atlas database even though my IP is whitelisted

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.

Connect to MongoDB database using mongoose behind a proxy

I am using mongoose to connect to my database in mongolab in my server.js file :
mongoose.connect('mongodb://MyUsername:MyPassword#ds089702.mongolab.com:89702/todo');
When i launch my server with node server.js command, i see this error in my terminal
failed to connect to [ds089702.mongolab.com:89702]
I am very sure that is just a corporate proxy problem, so I'm wondering how can I connect to my database over the corporate proxy using mongoose ?
Thank you!
I had the same problem and figured out a solution that worked for me.
Example mongodb URI:
mongodb://:#ds123456.mlab.com:37409/dbName
Use a proxy client (e.g. Proxifier).
Create a HTTPS proxy through port 8080 using your corporate proxy as the address.
Create a rule for mlab using your URI's port as the target port, which uses the HTTPS proxy you created above as its action.
Prioritize your mlab rule high in the rules list.

Resources