0

I am trying to connect to Remote MongoDB using the below credentials from ROBO3T and it is getting connected successfully.

enter image description here

enter image description here

enter image description here

I am trying to replicate the same through .sh file i.e, shell script and it is not working.

1) This is the command I am executing frm mongo shell script ,

mongo --username username --password password --authenticationDatabase admin --host ip-test --port 27017

But I am getting Socket Exception and COnnection Timed Out Exception and not able to connect to Remote MongoDB.

2) So, I have added the below ip in mongo.cfg file,

bindIp: ip-test,127.0.0.1,0.0.0.0

3) I have also have ip-test defined in windows Host file as well.

4) I have also tried the below command after all configuartions ,

mongo -u username -p password ip-test:27017/sample --authenticationDatabase admin

But still getting same Socket Error and Connection Timedout.

5) Then I tried giving the ssh Tunneling (configuration) in the mongo shell command itself as below,

mongo ip-test:27017/sample -u username -p pasword -e 'SHOW DATABASES;' -h 127.0.0.1 | ssh -fN -l root -i "path for private key/id_rsa" -L 22:ip-test:27017 ip-test

This is not giving any Socket Exception, but its giving Connection Timedout.

When i try to connect ssh independently from terminal, its successful.

But the issue is I want to combine mongo shell command with both authentication and ssh tunneling in a single command.

Can anyone help me in understanding, how to get connected to Remote MongoDB server with Authentication and SSH configurations via .SH file(Shell Script)?

I am very much new to ssh Tunneling with shell script, need kind help.

Thank you so much in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.