I have mongodb installed on aws ec2 up and running. Now i want to connect that mongodb to my Robo3T client. So in connection tab i put my public ipv4 ip in address field, put 27017 in port(connection tab).
Then in SSH tab of Robo3t i again put my public ipv4 ip in SSH address field and put 22 in port field. in SSH User Name field i put default ubuntuand select private key method from dropdown SSH Auth Method field. Then i browse my .pem file. But it is not connecting and giving me this error
What am i doing wrong?
I also have done port configuration on aws. Please see below :
You need to set Address: localhost
Related
I have started learning MongoDB, I am just trying to connect to the database using MongoDB Shell.
I am using the below command.
mongosh "mongodb+srv://cluster0.12345.mongodb.net/myFirstDatabase" --username viveknuna
I have added my current IP Address to IP Access List. But getting this error.
MongoServerSelectionError: connection to closed
I have referred to this question and added 0.0.0.0/0 (Allow access from AnyWhere) in the IP Access List. and it works as expected. But this is a security risk, Is there any way without allowing all IPs.
FYI: I am inside Virtual Machine and running this command also from VM.
in my case when i got these error MongoServerSelectionError: connection <monitor> to 16.163.195.9:27017 closed
I actualy put the wrong ip address i put my private ip; thats why.
i fixed it by changing the ip address in the IP List from WAN IP to my Public IP address thats how i fixed it, just search what is my ip, in you favorite seach Engine and it will show you your public ip in the result.
For me this error was occurring because my connection string was wrong.To be very specific - I copied the sample connection string from a course I was learning and just replaced the username and password with my credentials. So, the credentials were right but not the rest of the connection string.
Just for the sake of understanding. Please see below :
mongodb+srv://myusername:mypassword#courseproject.h1mpg.mongodb.net/?retryWrites=true&w=majority"
myusername and mypassword are correct i.e belongs to my cluster in MongoDB atlas account, but the rest of the string is wrong as I copied it from somewhere instead of copying it from my own MongoDB atlas account.
So please make sure to double check if your entire connection string is correct.
This happens when your ip address on the remote mongoDb is not the same as the public ip address of your computer. Simply go to network access on atlas and add your public ip address. Also, if your ip address is the same as that on the remote mongoDb then probably the connection closed after some period(default is 6hours).Thus when adding a your ip, unsure you toggle and set the duration for the connection (max is a week)
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
I am not able to connect my server in MongoDB Compass. I am trying to connect by identity file. I am providing hostname username and file.
I got:
'Error creating SSH Tunnel: Timed out while waiting for forwardOut'
What does it mean?
Hi, krl! I was getting the exact same error from MongoDB Compass Community 1.11.1 while trying to connect through an SSH tunnel, with a ppk file protected by a passphrase.
Are you putting your remote server IP or domain name in the first field (hostname)? That was my mistake.
What solved it for me was setting the Hostname field (the first one on top) to localhost instead of remote server IP or domain name. Put your domain/IP only on the field SSH Hostname.
I hope it helps.
I can successfully connected with mongodb on SlamData but for my localhost. Now I have a mongodb database on my EC2 server that database i want to connect in Ec2 then How can I ?
I know username and password. What should be a host and port?
If you are running Slamdata on your host and want to connect to MongoDB running on a remote EC2 host.
Then apart from the username and password, the host is the Public IP or host FQDN [ec2-xxxxxxx], port is 27017. For this check if your mongos is running and binding on 0.0.0.0. If it is binding to 127.0.0.1, you cannot connect remotely
Also check you AWS security group for EC2 and see that the port 27017 is open for your IP or in general to all [0.0.0.0] (this is NOT recommended!!!)
You can also review the FAQ on docs.slamdata.com located here.
Provides step-by-step troubleshooting for connecting to cloud-hosted MongoDB servers.
Additionally, the Path value refers to path inside of SlamData rather than the operating system path. For instance entering a value of aws1 results in a query path similar to the following, assuming you have a databased named demo and a collection named coll1:
SELECT * FROM `/aws1/demo/coll1`
we have an EC2 MongoDB 2.4 instance from Amazon MarketPlace.
when i try to access it from my computer using the mongo command like so:
mongo xx-xx-xx-xx-xx.compute-1.amazonaws.com
i get the following error
Error: couldn't connect to server xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
i can connect to the remote instance using ssh so it is reachable.
the port is the default port 27017.
mongod is running and working on the remote instance.
any suggestions on how to fix this?
As frisky said, you have to open the port 27017 at the EC2 Security Group Console.
(To know more about how to do that: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html)
But you also need to change the bind_ip variable at the /etc/mongodb.conf file. You need to comment the line or assign the ip that will be able to connect the DB to it.
The following two steps enabled the remote connection for me:
Opening the inbound rould for my VPC at port 27017
VPC -> Security -> Security Groups -> choose your instance's TCP roule -> click "Edit Rules" -> add a rule with Type: "Custom TCP Rule", Protocol: TCP, Port Range: 27017, Source: Custom 0.0.0.0/0 -> save
SSH into your instance -> sudo vi /etc/mongod.conf -> set bindIp: 0.0.0.0 -> save -> sudo service mongod restart
After that you will be able to connect into you remote mongo instance with mongo --host YOUR_INSTANCE_IP
Since mongod is running and working on the remote instance, you can access your MongoDB content via
mongo xx-xx-xx-xx-xx.compute-1.amazonaws.com or
mongo machine_elastic_IP
Before that you need to open Inbound port for that machine.By-default port 27017 is closed for external world.
For more info refer : http://docs.aws.amazon.com/gettingstarted/latest/wah/getting-started-security-group.html
Amazon created mongo security group without 27017 open.
opening port 27017 to my pc fixed the issue.
Try to access xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 from browser, if it works then ssh into the instance.
Stop the mongodb server
Remove the file /var/lib/mongodb/mongod.lock
start the mongodb server again, and check if typing mongo takes into a mongo shell or gives any error.
If the error is present, exit from the instance and again ssh to check for $mongo, if it opens a mongo shell. Try a reboot after this changes if the error still exists after the above changes.
The only concern here is, before accessing it from any application. Mongodb should work independently in the terminal.
EC2 controls access using security group, so make sure that box accessing mongo db host is in the security group allowed to access this box and port is enabled for the same security group.
Another problem can be iptables. Check sudo service iptables status on the mongodb box and see what are the rules there.
Make sure there you enable appropriate ports as per security requirement of the box.