12

I have Docker installed and am running a MongoDB container for my local development on my Mac. The problem is that I can't connect to said DB easily from CLI. I have Robo 3T installed, but I would prefer to use the CLI client instead.

Is there a known way to install JUST the mongo shell (command mongo) and not the full DB distribution on OS X?

8

You can download the latest Mongo Shell for MacOS from the following URL:

https://downloads.mongodb.org/osx/mongodb-shell-osx-ssl-x86_64-3.6.2.tgz

For the sake of completion, the Mongo Shell for Windows is available at https://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.2-signed.msi

Furthermore, for other Linux distributions, I suggest you create a MongoDB Atlas cluster (for instance, a free M0 cluster) at www.mongodb.com/atlas where you'll find the Mongo Shell downloads for all OSes in the Connect dialog of your cluster.

I hope this helps.

  • O.P operating systems environment is Mac-os-x. How he will install 'mongo shell' in that environment. And how will be set the default port 27017 there. – Md Haidar Ali Khan Jan 29 '18 at 11:42
  • @MdHaidarAliKhan The MacOS tarball (tgz) link in this answer is the minimal download asked for in the question: a ~10MB download which only includes the mongo 3.6.2 shell binary and the accompanying license notices. There really isn't an install step aside from unpacking the tgz file (double-click to open) and running bin/mongo to connect to an existing MongoDB deployment with appropriate connection parameters. An alternative would be to download the full MacOS distribution (~90MB) and only run the bin/mongo command. That would leave other tools like mongodump available if needed. – Stennie Jan 31 '18 at 9:58
  • Thanks Rahael. Very useful answer. Just what I was looking for. – Jannie Theunissen Jul 10 '18 at 11:13
  • @Md Haidar Ali Khan no need to set the port, 27017 is the default. You only need to set it if the server is different. – mckenzm Mar 15 at 5:13
1

I don't think so in macOS whitout installation of MongoDB ,you can able to connect mongo shell. To install MongoDB Community Edition on macOS system Install MongoDB Community Edition on macOS You may download MongoDB Community Edition through either the MongoDB Download Center or the popular macOS package manager Homebrew.

As The mongo Shell is an interactive JavaScript interface to MongoDB.

Note: Ensure that MongoDB is running before attempting to start the mongo shell.

For your further ref Here and Here

0

I understand you have mongo running on Docker, so as a workaround you can use the same running container to connect:

docker exec -ti $container_name bash
bash-4.2$ mongo -u $MONGODB_USER -p $MONGODB_PASSWORD $MONGODB_DATABASE
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3

Ideally you could connect with just one command but I don't know why is failing when calling from outside:

# this fail but you can use with other databases
docker exec -ti $container_name mongo -u $MONGODB_USER -p $MONGODB_PASSWORD $MONGODB_DATABASE

The idea is simple, mongo is installed on the container so you tell docker to run from inside the container. If you need to load files from outside you always can mount a volume.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.