how to connect same mongodb (in compass using hostname: localhost and port : 27017) local in 2 different PC's [duplicate] - node.js

I follow this mongoose document enter link description here
mongoose.connect('mongodb://localhost/waterDB');
Using This, I can connect local machine waterDBmongoDB DataBase
My Personal Machine Local IP : 192.168.1.5
My Server Machine Local IP : 192.168.1.100
Both machine have waterDB DataBase . There is no username and password for both DB
I wanted to connect Server Machine waterDB Inside My Personal Machine.
According To This : mongoose.connect('mongodb://username:password#host:port/database?options...');
I try : mongoose.connect('mongodb://192.168.1.100:27017/waterDB');
But,
MongoError: failed to connect to server [192.168.1.100:27017] on first connect
at null.<anonymous> (/home/water/node_modules/mongodb-core/lib/topologies/server.js:313:35)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
..........
Any solution for err ?
Thank (#_#)

It might be a problem with your MongoDB instance listening on localhost only.
You can change the bind address in MongoDB's configuration file. The config file may be located in /etc/mongodb.conf or /etc/mongod.conf. There are also 2 config file formats:
Old format (still supported):
bind_ip = 0.0.0.0
YAML (version 2.6+):
net:
bindIp: 0.0.0.0
After changing the config file you have to restart the MongoDB server.

Try without the Port no.
mongoose.connect('mongodb://192.168.1.100/waterDB');
this should work for you.
But make sure both are connected on the same network, if you are connected on other network than your server is, then it wont work

You will have to use SSH tunnel in this case. Refer to the following link which shows how you can create SSH tunnel.
Node.js SSH Tunneling to MongoDB using Mongoose

For me (using windows and mongo version 6, and remotely connecting from Mac), after changing config file to
net:
port: 27017
bindIp: "*" # OR 0.0.0.0
Then starting server with: mongod, it was still binding to 127.0.0.1 (localhost). I had to start the server with: mongod --bind_ip_all

Related

compass refuse to connect to remoto mongodb

I am trying to connect with my MongoDB data base using compass or through my NodeJS app but it refuse to connect, It was working but suddenly it now not ,I am using windows 11
I have try to connect it from the PowerShell using this and it actually connected
mongo "mongodb+srv://<username>:<password>#cluster0.oeari.mongodb.net/dbname?authSource=admin"
I tried edit the security in config file in bin folder but nothing changed , I also have configure the IP address option in MongoDB to accept connect from anywhere but still the same
security:
authorization: enabled
net:
port: 27017
bindIp: 0.0.0.0

Connect local postgres database from PGAdmin Container

I am trying to connect to my local postgres database from PGadmin in container, but it is through following error:
Unable to connect to Server: connection to server at "localhost" (127.0.0.1), port 5432 failed. connection refused is the server running on that host and accepting TCP/IP connections?
configurations i am trying for creating server are as follows:
hostname/address = localhost
port = 5432
username = postgres
my OS configurations
OS = Linux- Ubuntu
Version = 18.04
PS: there are some existing questions regarding this on Stackoverflow, but no solution helped me.
While it runs locally, the docker container is like a different machine. You need to put the IP address of the local host machine instead of localhost.

Connect and allow multiple ip's for mongodb accepting connections

I have a mongodb config file where bind ip is 127.0.0.1
Now mongodb is hosted on one instance and nodejs server is hosted on another instance which ip is (dummy ip) 184.54.125.132
On my mongodb Config file is
net:
port: 27017
bindIp: 0.0.0.0
By this my node server connect because it allows all (which is wrong)
How I add localhost ip of mongodb and my node server ip on bindIp so that mongodb server will listen only through node server and mongodb local.
I tried
bindIP: [127.0.0.1,184.54.125.132] //Not work
I tried
bindIp: 127.0.0.1,184.54.125.132 //Not work
I tried
bind_ip: [127.0.0.1,184.54.125.132] //Not work
I tried
bind_ip: 127.0.0.1,184.54.125.132 //Not work
Anyone suggest me where I am doing mistake. I also enabled authentication
It should be :
bindIp : 127.0.0.1,184.54.125.132
And dont forget to restart your mongod, after changing the config file, otherwise it wont work.
sudo service mongod restart
or
sudo systemctl mongod restart
.
Also, dont forget to open the port so that outside network can access that port(27017 or whatever port your mongodb is hosted on).
If you are using AWS EC2 to host your mongodb, you need to add that port to your inbound security rules, and that specific IP wherever you want to access it from

As I can, configure the firewall of ubuntu server for the server to accept connections of the terminals through PostgreSQL port 5432

Configuration: Server: Ubuntu server 16.04 LTS using webmin
Terminal: Windows 7 Using PgAmin III
I was unable to establish the connection between my terminal and my server through pgAdmin III on port 5432.
On my server I added:
in file postgresql.conf I edited
in #Connection Settings
listen_addresses = '*'
in file pg_hba.conf I added
in #IPv4 local connections
host all all 172.x.x.x/32 md5 //this is IP Terminal (Hidden x)
I checked the port, this is 5432 default and user is postgres
When I try to establish the connection on PgAdmin III:
Host: //My Server IP (Ping console successful)
Port: 5432
username: postgres
password: //My password
Show me the following message:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "Mi SERVER IP Hidden" and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.

Accessing MongoDB from Windows & Mac Client Machines

I have MongoDB 3.2 installed on my Linux Red Hat server.
I am starting to access it and looking at the mongo Shell instructions.
For a Windows machine, the instructions want me to get to the command prompt and change dirs to the installation directory. The problem is, MongoDB is installed on my web server and not my local windows machine.
Question: does Mongo Shell apply to me then? How do I start using, connecting and accessing Mongo from my Windows and Mac machines?
[Note: I am a traditional MySQL / phpMyAdmin developer looking to advance to MongoDB]
Amendments:
(1) With the help of #AlexBlex I am progressing to trying to connect to my MongoDB on my server from Robomongo on my windows client. I get the following error when trying to setup my connection. I tried the address with just my server ip and with http://{my server ip}. Neither worked. See screen shot of error
(2) This is what I have in my current mongod.conf file:
#port=27017
bind_ip=127.0.0.1
(3) here is what my connection settings look like. Oddly, #AlexBlex's solution below shows an SSH tab on his Mac version. The Windows and Mac versions I just installed lacks that tab.
If you install MongoDB on your local machine, you can use the Mongo shell like below to connect to your remote server
mongo yourserver:27017/database
You will have to configure your Mongo server to allow remote connections. In order to achieve this you need to have the following line in your /etc/mongodb.conf file. You need to replace 10.0.0.2 with the ip address of your client machine.
bind_ip = 127.0.0.1,10.0.0.2
You need either ssh to the server where mongodb is installed, or install mongodb on local machine.
For robomongo to connect to remote host you need to ssh to the server, and check it listens on external interface:
lsof -i | grep 27017
In case it is bound to localhost only, you need to edit a line with bind_ip in /etc/mongodb.conf and restart the service.
I would recommend to keep it listening on the local interface only for security reasons, and use ssh tunnelling to connect:
I found the answer. #ShahNewasKhan is brilliant. See How to connect Robomongo to MongoDB
All you need to do is SSH to server and edit mongod.conf file:
uncomment #port=27017 to port=27017
comment bind_ip=127.0.0.1 to #bind_ip=127.0.0.1
restart mongodb via service mongod restart
Then create a mongo connection via your server ip in the address field and 27017 in the port field
Hope this helps mongo newbies and start-ups like me :) Good luck.
Now I just need to figure out how to make this secure. My concern is that anyone who knows my server ip can hack into my MongoDB

Resources