connect to mongodb production using robomongo client - node.js

in my dev enviorment I use mlab as temp db, but now I have production db setup in my ubuntu server. I can run mongo in my terminal after I ssh into my server, now I'm having problem connecting it with my client software which is robomongo. What step I missed out?

In your mongo (mongod) configuration file (default /etc/mongod.conf), you have to set the net.bindIp setting to ::,0.0.0.0 to bind to all IP addresses what can access to db or you can set only your pc ip address (robomongo belong to the pc) and your node server ip (localhost if nodeserver is the same with db server).

Related

Why connection to postgres from nodejs is not working?

I have back-end created in nodejs hosted on Debian server using postgres 14.
the Nodejs listenning on port 5000, and when I try to connect to postgres using port 5432, I am getting the following reponse from Postman:
"Password is invalid".
I was trying the postgres role, and to create a new role, and problem is the same.
I was installing postgres on my Windows 10 computer, and all works fine in my localhost, but on the remote server not.
My Nodejs back-end, and postgres are on the same computer, but each role I've tryed won't connect to the database.
There is pg_hba.conf in /etc/postgres/14 on your server you have to add:
host username database 0.0.0.0/0 md5
This would allow connection to database from any host to username using password authentication.
Also there is a pg.conf or postgres conf
There is line allow_connections the value should be '*'
allow_connections='*'
This would generally allow connections to postgres running on that server
Guide https://coderwall.com/p/cr2a1a/allowing-remote-connections-to-your-postgresql-vps-installation
don’t forget you have to reload postgres after config change:
systemctl reload postgres

can not connect to postgres db from node server

I want to connect my apps nodejs using node-posgres to PostgreSQL. My apps in linux server and my postgresql in another linux server by 176.9.154.123 IP.
this is my error:
this is my pg_hba.conf:
host all all 176.9.154.123/32 trust
i can solve this problem by add this line to postgressql.conf:
listen_addresses = '*'

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

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

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

How should my local server communicate with an EC2 server?

I have a node.js server running on ec2. I'd like for that server to automatically push data to another node.js server that is running on my laptop.
What is the best way to do something like this?
You could use a service like showoff.io to create an entry point to access your local laptop, or you could just create an SSH tunnel by running this command on your laptop:
ssh -R port:localhost:remoteport ec2-host
That will allow port on the loopback interface of your EC2 server to connect to remoteport on your laptop.
Then just modify your code to connect to the node.js program running on your laptop via the IP of 127.0.0.1 and port of port.
You could have the EC2 node.js call a function from the local node.js, and pass the data as variables

Resources