how to connect mongodb via COMPASS is bastion host(jump) setup - mongodb

So I am using a bastion host(jump server) to connect to mongo db. I can use it via command line but I want to connect via compass.
So I am having an ec2-A(public) which uses ec2-B(private) to mongo db. I now how to do it on windows via putty but how to do it on mac??
Using this to connect jump server
ssh -i ~/B.pem -o "ProxyCommand ssh -W %h:%p -i ~/A.pem ubuntu#ec2-xx-xx-xx-xxx.eu-west-2.compute.amazonaws.com" ubuntu#1xx.xx.48.xx
and then mongo connection command.

Related

Atlas MongoDB SSH Tunnel hostname mismatch

I am trying to setup an SSH tunnel to a mongoDB cluster hosted In Atlas. I setup the tunnel with the below command
ssh -i <key_file> -N -L <localport>:<atlas_node_hostname>:<atlas_port> <remote_user>#<remote_ip>
And added the atlas_node_hostname in
/etc/hosts
From the machine where I created the SSH tunnel, I can connect to atlas db with the atlas_node_hostname mentioned in the string.
mongo --ssl "mongodb://<username>:<password>#<atlas_node_hostname>:<ssh_tunnel_local_port>/<db_name>?authSource=admin"
But I want to connect using 127.0.0.1 instead of the atlas_node_hostname, this is so that I can give devs access only to the machine where the tunnel is running and they can connect to the DB.
mongo --ssl "mongodb://<username>:<password>#<127.0.0.1:<ssh_tunnel_local_port>/<db_name>?authSource=admin"
But with the above attempt I get the below error
Error: couldn't connect to server 127.0.0.1:27779, connection attempt failed: SSLHandshakeFailed: The server certificate does not match the host name. Hostname: 127.0.0.1 does not match SAN(s): *.345ed5412fd76fb84cd13794.utkqs.mongodb.net, *.utkqs.mesh.mongodb.net, *.utkqs.mongodb.net, CN: *.utkqs.mongodb.net :
Is there any way I can get it working with the 127.0.0.1 instead of giving the atlas_node_hostname? Or any tool that can proxy Atlas MongoDB?

Unable to connect to remote host from Mongo Shell

i am trying to connect to a remove Mongo server from Mongo shell but when i run the mongo shell it keeps connecting to the localhost by default, if i enter exit to connect to another mongo server, the shell closes
i tried changing the mongod.cfg file and set the remote server ip and port but it did not work
i tried to connect to the remote server from the windows CMD but i keep getting this error SASL mechanism 'PLAIN' is not supported
how can i change the default connection of the mongo shell to connect to the remote mongo server?
mongod.cfg is for your local mongo server. Changes in this file have no effect on the client/shell.
The authenticationMechanism parameter in your command should agree with remote server configuration and authenticationDatabase should be the one where the user is registered on the remote server.
There are good chances authenticationMechanism is default SCRAM and the database is "admin".
Try mongo -u 'username' -p 'password' --authenticationDatabase admin host:port/db

How do I do mongodump on a server and transfer that to my local machine using golang?

I wrote a go program ( which is basically the code in this example, Simple SSH port forward in Golang ) that connects to a remote mongodb server by creating an ssh tunnel. I can query the server using mgo api. Now, instead of querying the server everytime, I want to copy a few collections of the database to my local machine and query locally. It is important to note that I cannot copy it directly to my local machine as there is port forwarding involved. How can I achieve this ?
You are reinventing the wheel. Use cron to create an ssh tunnel to the destination and then use a local mongodump to connect against your local tunnel endpoint
ssh -f user#mongodb.example.com -L 27017:mongodb.example.com:27017 -N
mongodump localhost:27017 <your opts here>

How to connect Zeppelin to a database that is through an ssh tunnel

I have a local zeppelin instance running on my mac at localhost:8080 and I am trying to connect to a postgres database that is remote. I can access it via ssh and have set up a key pair for my computer but I can't figure out how to have zeppelin query the db directly
I don't think Zeppelin currently support database connection via ssh.
But you can still use a ssh tunnel and connect to your database.
1/ Start a tunnel by running this in a console :
ssh -i PATH_TO_KEY -L 5432:localhost:5432 USER#HOST -N
Where USER is the username associated the key pair and HOST is the ip address of your postgres host
2/ Create the zeppelin interpreter as if postgres was running locally
(this means default.url = jdbc:postgresql://localhost:5432/ )

mongodb installed in azure ubuntu cannot connect

I am trying to connect to a mongodb database I installed on an Ubuntu VM on Microsoft Azure. I did the following:
Created virtual machine.
sudo apt-get mongodb (I connected to the VM with ssh).
Created an Endpoint on the Azure Management Portal with both public and private ports set to 27017.
When connected via ssh, running the mongo command allows me to view and access the data stored in the mongodb, but when done remotely, the connection fails with:
Sat Oct 11 13:34:08.378 JavaScript execution failed: Error: couldn't connect to server xxxxxx.cloudapp.net:27017 at src/mongo/shell/mongo.js:L114
I think I am missing something pretty basic here. Hopefully someone out there can help me?
It looks like mongo has some problems when connecting with a regular string. Might be related to this JIRA.
Try to connect with the following syntax: mongo -u <user> -p <password> hostIP:port/db
make sure you unbind the IP for connecting remotely to it by editing:
sudo vi /etc/mongod.conf
Set bind_ip=0.0.0.0
sudo service mongod restart
to test, use: `mongo SERVER-IP:27017/DBNAME -u DBUser -p DBPass