Heroku and MongoDB atlas connection - node.js

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.

Related

How to find mongodb server ip

I am creating a MERN stack app. Right now I need to get the MongoDB server IP. They suggest using nslookup tools to get the IP address. Can anyone suggest me how to do that?
What thing should be added after nslookup?
You have to add your mongodb server cluster URI after it.
Example:
nslookup ds-shard-00-00-17jcm.mongodb-dev.net
Here is more information:
https://www.mongodb.com/docs/atlas/reference/faq/networking/

I am not able to connact to MongoDB atlas?

I am trying to connect my MERN stack project to the MongoDB atlas. through this link
mongodb + srv://myUserName:myPassoword#cluster0.wbrda.mongodb.net/myCollectionName?retryWrites=true&w=majority
this link was added to my application 2-3 days ago and it is working perfectly till 5 hours ago. Now it is not working, throwing error
not connected 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/
this type of problem occurs to me a lot of time, but whenever I put a new link problem gets resolved but at this time I am not able to do it.
what is the permanent solution to that type of error?
please help me to get it out of this error.
Atlas only allows client connections to a cluster from entries in the project’s IP Access List. Each entry should either be a single IP address or a CIDR-notated range of addresses.
You have to add your IP to the white list.
in your mongo account:
got to security section => Network access => ip access list.
then edit the ip:
you can either choose add current ip address choice, or you can add 0.0.0.0/0 manuelly(which includes your ip as well)

Can't access to postgreSQL server

I'm having a trouble which I can't connect to my database using IP Address. It works fine when I access it to my local but the problem is the other PC can't connect to my server. I've been using postgre v11 and navicat v12. Is there any permission to setup in my device in order that the other devices can access to my database? It would be great if anybody could figure out where I am doing something wrong. thank you so much in advance
You have to change the host settings of the database to access it from a foreign IP
I would look at two things if connections from remote hosts are being rejected.
First what is the value of the parameter listen_addresses in the postgresql.conf file? If it is set to:
listen_addresses='localhost'
It will be allow only local loopback connections. Change this (for example to listen on all interfaces) to:
listen_addresses='*'
Next, check the pg_hba.conf file has a rule to allow connections from your remote client. By default PostgreSQL will refuse these remote connections and they must be whitelisted. The following example entry would allow any user to connect to any database from 192.168.1.2 and they must supply the password
host all all 192.168.1.2/32 md5
Check out the official PostgreSQL docs for this at:
https://www.postgresql.org/docs/11/auth-pg-hba-conf.html

How do I get the exact IP address of my mongodb database?

I am trying to deploy my node app to my Cpanel however the page times out with an error
503 Service unavailable
The website works on Heroku, ngrok and localhost however on my hosting service, it doesn't.
I found out that the issue was due to port 27017 not being open.
On discussing with my hosting providers, they said
"We can open the ports for you but our policy is to open non-standard ports to specific IP's for better security of the server. Is it possible to get the exact IP addresses of the database server you are trying to connect to."
So I'm not familiar with mongodb database having a specific IP address. What could they mean?
To connect to your db, your node app needs a URL something like this.
const url = 'mongodb://hostnameOfMongo.example.com:27017'
Your database's hostname is the stuff after mongodb:// and before :27017.
Open up a shell (a command window) and type
ping -n 1 hostnameOfMongo.example.com
or maybe
ping -c 1 hostnameOfMongo.example.com
It should show you the IP address associated with your mongo server.
(Obvs, put your actual db hostname into the command, not my example.)
It's a little strange that your hosting provider didn't ask for the hostname when you didn't know the IP address. If they were my hosting provider, my confidence in the competence of their support would go down a notch because of that.
And please be aware that running a db in one data center and a node app (or indeed any app that uses the db) in another data center is a formula for poor performance and unreliability. The app and the db work best with a short and private network connecting them. With respect, it doesn't seem likely you have the network engineering chops to make that sort of thing stable and reliable.
Not to mention the security problems with exposing mongodb to the public network. Your hosting service is reluctant to open a port for a very good reason. Read this. Because cybercreeps

Meteor: Remote MongoDB with dynamic IP

In a local network (over which I supposedly have no control) I need to connect my local instance of a meteor app to a MongoDB that is running on another PC. Using something like MONGO_URL="mongodb://192.168.1.xx:27017" meteor I am able to connect to it; However is there some way to connect when I don't know the IP, given that it may change daily?
What I'm attempting here would be something like:
Meteor.startup(() => {
//Script to find the correct IP
//Connect my app to that MongoDB instance
});
In short: is there some way to set the MONGO_URL dynamically?
Thank you
Use the hostname of the MongoDB server. As long as you have a local DNS server and both computers are using the same DNS server (which is most likely the case unless you have customised the network settings on either PC), the name will be resolved to the IP address.
To get the hostname of the server, type hostname into Command Prompt (or Terminal if on a Mac).
Alternatively, even without control over the network you may be able to configure a static IP address on the MongoDB server as long as you have local administrator permissions. Just make sure it is within the same network range as the rest of the network, but try to steer clear of your DHCP range otherwise you may get IP conflicts.

Resources