How to connect VPS to MongoDB Compass - mongodb

I bought a VPS and I want to put MongoDB server there. I connect to VPS with ssh tunnel, install MongoDB and start it.
The question is, that how can I add VPS server to MongoDB Compass? Is it even possible?
I was trying to connect via hostname but I receive this error - connect ECONNREFUSED my.ip.adress.here
Also was trying to connect via ssh tunnel in MongoDB Compass - doesn't work for me.
Maybe there is a problem with port?
I can connect to my VPS from terminal with ssh.
Edit1:
I was using this documentation to install MongoDB on ubuntu and I'm using MongoDB 4.2.8
EDIT2: When I install mongodb on VPS, MongoDB ip is 127.0.0.1 how can I change it? I want it to set it for VPS ip address. If it's possible, otherwise I don't understand how I can connect to my DB on VPS.
Sorry if it's lame questions, just first time using VPS and it's pretty complex to me.

Before you can connect to vps with mongodb compass, you need to allow remote connections to mongodb from your vps.
It is recommended to secure your mongodb connection with a username and password
Edit the mongod.conf file located at
sudo nano /etc/mongod.conf
Enter a comma and append the IP address of the vps to the end of the bindIp field. This will allow remote connections to the mongodb instance
Save the file and restart the mongodb connection
sudo systemctl restart mongod
Setup the firewall to allow connections to port 27017 (the default mongodb port) from anywhere. (Please note that will expose your mongo database to the internet. Therefore it is recommended to close this port when shipping to production)
sudo ufw allow 27017
That's it for the vps.
You can now open up mongodb compass
Choose "fill in connection fields individually"
Fill in the hostname with the IP address of your vps, port is the port which you opened previously 27017 in this case and select authentication by username and password.
Enter the username and password of the mongodb admin which you should have created already.
Choose the authentication database (usually admin)
That's it. You should be connected. You can now view the collections and fields of your mongodb instance on your remote machine

Related

Having problem in connecting to remote MongoDB Server

I tried to connect a remote MongoDB Server running on Ubuntu using MongoDB Compass on Windows. But I have problems connecting always as the IP of the Windows machine changes every day.
I did the following things to connect to the remote server-
Got the IP of the Client Machine, then allowed that IP on the firewall of the server machine on port 27017.
sudo ufw allow from client_machine_ip to any port 27017
Note: The ufw status looked okay.
Got the IP of the Server Machine, then on the MongoDB configuration file on the server, I modified the bindIp.
bindIp: 127.0.0.1,server_machine_ip
Note: I restarted mongod and it was okay too.
I was able to connect the remote MongoDB Server using MongoDB Compass successfully for the first time. Then I saw, the IP of the client machine was changing every day. So, every time, the client IP changes, I need to allow that IP on the firewall of the server machine (in which I am using the MongoDB Server) on port 27017. Could you help to solve this? Thanks in advance.
You can update the firewall for port 27017 to allow from anywhere since client machine IP is not static.
sudo ufw allow 27017 #(this will allow from any IP)

How to connect to DogitalOcean Droplets database with MongoDB Compass?

I have a flask app with mongoDB running on a digital ocean's droplet, and now I need to see what's inside that database.
I'm trying to connect with mongoDBCompass, but no tutorial seems to help me.
If there's another easier way to access that data, it would be helpful too.
You have several options:
Connect MongoDB Compass via an SSH tunnel.
Or use SSH tunneling with e.g.:
ssh -L <local_port>:<mongodb_hostname>:<mongodb_port> <user>#<bastion_hostname> -fN
and connect MongoDB Compass via localhost:<local_port>.
Or use the mongo shell directly on your droplet.
Or open the mongo port (typically 27017) via an inbound firewall rule and connect your favorite client to your droplets public IP.

Connect mongodb server via robomongo from another PC

I am using mongodb database for my meteor app. I want to access it from another pc. I have mounted my local as a virtual drive on other PC using ssh. Now I want to connect to mongodb via robomongo. I have given the address as 192.168.1.2:4001 (ip addr of local : port on which meteor is running +1). But its giving an error 'Unable to connect to mongodb'. How to proceed?
The other way around is to start your meteor on a regular mongo server with this command :
MONGO_URL=mongodb://localhost:27017/nameOfDatabase meteor
Be sure to have a running mongo on localhost and to change the nameOfDatabase.
Now it's just a regular mongoDB server to connect. Also you might need to add login and password to that mongo url and the debug parameter after meteor if you use packages like meteor toys.
Please check mongodb's config file /etc/mongod.conf and comment out bind ip
net:
#bindIp: 127.0.0.1
port: 4001
Restart mongodb service. This will allow mongodb to bind to ip's other than localhost.

Connecting to Meteor Mongo from GUI

How do I connect to my Meteor Mongo instance from a GUI, e.g. MongoChef (I am on Windows running an Ubuntu Virtual Machine which has the Meteor application on it)?
I have tried connecting using the IP address of my running Virtual Box, with both port 3001 and 27017 with no joy - should I be setting up some port forwarding or something?
This applies to an out-of-the-box install of Mongo when Meteor is installed:
The mongo daemon mongod binds to 127.0.0.1 so you need to connect to it via a SSH tunnel if your client supports it. MongoVUE and Mongo Chef both allow this type of connection. Once you SSH into the VM, you can connect to 127.0.0.1:3001 without any trouble. It does not require a password or username, just the database to be set as meteor.

Access MongoDB from other server

I have a MongoDB database on my Linux server. I want to access it from another server. I tried to make a connection from my local computer with the Robomongo. The connection is succesfull, but the authentication fails.
How can I get the authentication credentials? Or should I change something in MongoDB before I can acces the database from another server / pc?
Someone else have set up this database, and there is no possibility to ask him this questions.
I have found the solution by my self:
The File etc/mongod.conf has a line 'bind_ip'. In this line, you originally have to add the IP address which you want to access your database. But, it don't work! You should better comment this line.
But, you don't have any authentication now, so you have to add authentication. Here you have an tutorial about this: http://ghosttx.com/2012/03/how-to-connect-to-a-remote-mongodb-server-with-mongohub-for-mac/
When you have done that, you have to enable authentication. You can do this by editing etc/mongod.conf again, and uncomment the line 'Auth = true'.
Now you can connect with you Mongo Database ;)
Ive sorted it by adding ssh option to RoboMongo following this link:
http://www.mongovue.com/2011/08/04/mongovue-connection-to-remote-server-over-ssh/
Im on OSX and connecting to Ubuntu 14 / Mongo 2.6.7 on VPS and when Ive added my ssh details to the Robomongo all seem to work ok (Ive also changed the mongo config to remove the ip_bing and enabled port 27017)
If you do not like to bother with authentication and stuff just make an SSH Tunnel:
ssh -fN -l username -i .ssh/id_rsa -L 9999:localhost:27017 remote.com
Just connect to mongodb on localhost:9999 and it will establish a connection to your mongodb on port 27017 on your server at remote.com.
Run your mongodb with following command to access mongodb from other servers
mongod --port 10945 --bind_ip 0.0.0.0
I was not able to use Robomongo with MongoDB 3.0 too (connecting from a Windows machine to a Linux one, using SSH). The only tool that works for me is MongoChef (http://3t.io/mongochef/).