How can I connect to a remote mongo server from a Mac OS terminal

I would like to peek into the mongo shell in the terminal on my MacBook. However, I'm interested in connecting to a Mongo instance that runs in the cloud (compose.io instance via the Heroku hadron). I have a name, password, host, port and database name from MongoDB URI:

mongodb://username:password@somewhere.mongolayer.com:10011/my_database 

I installed mongodb on my MacBook using Homebrew, not because I want Mongo to work on my Mac, but just to access the mongo shell program to connect to this remote database.

However, I cannot find the right command to get me full access to the shell that I would like. Using the instructions found here http://docs.mongodb.org/manual/reference/program/mongo/ (search for "remote") I can get what looks like a connection, but without specifying a username or password I'm not completely connected . Running db.auth(username, password) returns 1 (unlike "auth fail" with an incorrect username and password), but I continue to receive an "unauthorized" error message when I issue the show dbs command.

+65
mongodb mongo-shell
Nov 08 '14 at 4:52
source share
2 answers

You may be connecting normally, but you do not have sufficient privileges to run show dbs .

You do not need to run db.auth if you pass auth on the command line:

 mongo somewhere.mongolayer.com:10011/my_database -u username -p password 

As soon as you connect, can you see the collections?

 > show collections 

If all this is good and you simply do not have administrator rights for the database and cannot start show dbs

+118
Nov 08 '14 at 5:24
source share

With Mongo 3.2 and above, just use your connection string as is:

 mongo mongodb://username:password@somewhere.mongolayer.com:10011/my_database 
+27
Jul 23 '16 at 9:26
source share



All Articles