How to use sslAllowInvalidHostnames in mongo connection string in mongo-shell script? - mongodb

I created a simple js script that uses two databases (ssh tunneled to ports 27019 and 27027), to run in with mongo shell.
Of those databases have slightly stricter rules - requires ssl connection and do not allow connections from localhost.
If I connect to second database from terminal with --sslAllowInvalidHostnames everything works fine, but I do not know how to add it to connection string, so I can use it in mongo shell script.

Try
sslVerifyCertificate=false
/dbname?replicaSet=XYZ&authSource=admin&ssl=true&sslVerifyCertificate=false

Related

Unable to connect to mongodb with compass, but can via mongo shell?

I'm really confused. I'm able to connect to mongodb with the shell but not compass via connection string or manually typing fields (the option at top right).
Here's the shell connection:
mongo --username myAdminUser --password password123 --authenticationDatabase myAdminDatabase --host localhost --port 27020
I've tried a few connection strings /?authSource=myAdminDatavase, /myAdminDatabase, I've even tried them together...
I'd love a single connection string that I can use in compass.
Here is the connection string the shell outputs once it connects:
mongodb://localhost:27020/isMaster?authSource=myAuthDatabase&compressors=disabled&gssapiServiceName=mongodb
I tried this with credentials also.
My environment is a little odd, but cannot be changed. I'm in a virtual machine, with a local k8s cluster hosting the mongo instance in a pod. These connections are all forwarded through to my host, which I use to connect to mongo from the shell and it works successfully.
The shell is fine, but sometimes just tweaking a document slightly via compass is convenient and a more pleasant experience.
If anyone could shed any light on this I'd massively appreciate it!
Managed to resolve it, SSL only supports single way tunneling, so I had to turn SSL off in my mongo instance and disable it on my connection string, this worked fine. Hopefully this helps anyone else working remotely and struggling.

Can't connect to mongodb remotely

I have a server on Digital Ocean running a MongoDB instance, if I ssh into the server, I can connect to the Mongo Shell with no problem. When I try to connect on my own machine, with PyMongo, it also connects with no problem.
The problem is when I try to connect from my machine via Mongo Shell, then I get
MongoDB shell version v3.6.3
connecting to: mongodb://<server_ip>:4131/?replicaSet=mongodb%3A
2018-06-26T11:50:05.799-0300 E QUERY [thread1] Error: '/<server_ip>:4131' in 'mongodb://<server_ip>:4131/?replicaSet=mongodb%3A' appears to be a unix socket, but does not end in '.sock' :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
So as some may have noticed, I did change the port to 4131, and yes, I pass this information on my connection string.
I have done a lot of research and already discarded some things:
No, there's no .lock file, and I have made sure to run mongod --repair just to be sure.
My /etc/mongod.conf has external ips enabled, (ie.: bindIp: 0.0.0.0)
Extra information:
There is a /tmp/mongodb-4131.sock file, which should be the socket mongo shell is looking for, right?
I looked up before changing the ports and made sure nothing was using 4131
Firewall is disabled (just to make sure that's not the problem)
Any help is appreciated.

JDBC connection to mongodb running on Meteor server on Cloud 9

I have a Meteor app running on Cloud 9 and I would like to connect to MongoDB from a window app that I am in trial period (DBSCHEMA: http://www.dbschema.com/).
Cloud 9 guys told me that I need my DB to listen to 0.0.0.0:8082.
In cloud9 I started my app using command: $ meteor --port $IP:$PORT.
I also created a db and user that has role "userAdmin" to this database.
In another terminal, at c9, "Meteor mongo" command give me connecting to: 127.0.0.1:8081/meteor
In DBSchema ping to the server is succesfull, but connection is refused.
So, I am trying to change to 0.0.0.0:8082 but I cant figure out how and not sure its going to work.
Any suggestions please?
use environment variable MONGO_URL=your-mongo-server-ip-or-hostname:8082 in meteor and start mongo with port 8082 on 0.0.0.0 with the config file
http://docs.mongodb.org/manual/reference/configuration-options/
Ideally, you should not expose you dB to the outside (so not bind to 0.0.0.0 which exposes the DB on all interfaces including the public IP).
If you want to access it with Robomongo, bind to localhost, and then you should create a ssh tunnel to the server from you local terminal with the command
ssh -L 8082:localhost:8082 your-host
then connect to it with robomongo at localhost:8082 –

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/).

How to connect mongodb clients to local Meteor MongoDB

How can I connect Robomongo (or any other mongodb client) to the mongodb instance that is created by my local Meteor application?
Ensure Meteor is running on localhost. Open a terminal window and run meteor command. It will start running on localhost:3000 if you have not changed to port.
While it is running, open a separate terminal window and run meteor mongo command. This will open up a MongoDB shell and tell you what port it is connecting to This is normally 3001 as of version 0.7.1.1 or 3002 if earlier. It will say something like 127.0.0.1:3001/meteor
Go to Robomongo (or your favorite mongodb client software) and create a new connection, making sure to change the connection address to localhost and the given the port number. No need to additionally define /meteor if your client does not insist on a default database.
Also as pointed out in https://stackoverflow.com/a/22023284/1064151 some drivers may need specific line endings, delimeters or other character flow. For example, ObjCMongoDB a C based driver wants the url to be 127.0.0.1:3001/ with that extra / at the end, or it won't work. So make sure you check the documentation for your driver/client.
Easiest way to get the current configuration details is to use the following command
meteor mongo -U
This will give you the connection string
From terminal run following command
meteor mongo -U
That will show you the local host IP address and in which port you application is running. Now run the Robomongo and configure as following two field as you got by running the previous command
Use SSH tunneling by the following command :
ssh -L 3001:localhost:3001 user-name#host
It forwards connections from your local port 3001 to localhost:3001 on your server. Now we can simply connect to our database.
Create a Robomongo connection on your localhost and hit Test (Out of two checks, Authentication may fail) :
I'm using ObjCMongoDB, a C based mongoDB driver. With the new update instead of using the previous 127.0.0.1:3002 to connect to my localhost running meteor's mongodb, I now need to use 127.0.0.1:3001/ with the collection name still being meteor.collection. The important change is the port from :3002 to :3001/. Remember the /, it is critical for the connection.
This worked for me,Before connecting make sure meteor is running.
I am using Robomongo to connect. Create new connection and add
Address as : localhost;
port as: 3001
I'm too using Robomongo and before the latest update V0.7.1,i used port 3002 to connect,as #Serkan Durusoy suggest's for the latest update it is working for 3001 port
#imal365 answer is perfect. Just to add my insight on it:
I realized that the default Meteor Mongo port number is the port number of the application with 1 added to it (as of version 0.7.1.1). In my case, I was running Meteor on port 1337 with the command meteor --port 1337 and my Meteor Mongo port was 1338.