Start MongoDB Mac - How to Start MongoDB on a Mac
In this article we’ll show you how to start MongoDB on Mac. The first section is for those who already have MongoDB installed and just need to start it. If you do not have MongoDB installed we have also included a section that will show you how to install it via Homebrew and then how to start it on your mac.
Starting MongoDB On Mac – MongoDB Already Installed
If you already have MongoDB installed starting it is super simple. All you need to do is open the Terminal and run this command:
This starts MongoDB in the background. You should see a long list of logs display but it should end in a log similar to this:
Note: You won’t be able to use this terminal anymore to run commands.
Installing MongoDB via Homebrew
Install MongoDB using Homebrew by running the following command in a terminal:
Running MongoDB after you’ve installed it via Homebrew
Now that you’ve installed MongoDB via Homebrew you can run it via the Terminal. Open up the Terminal program on your mac or whatever shell you’re comfortable with and start the MongoDB daemon by running the following command:
Do I Already Have MongoDB Installed?
If you’re not sure if you already have it installed you can run the command:
If you don’t get a response you don’t have it installed. You already have it installed if it returns a path like this:
You can also check if it’s been installed through Homebrew by using this command to see what’s been installed via Homebrew:
You’ll receive a list like this with the packages you’ve installed through Homebrew. If
mongodb is there then you already have it installed.
bash-completion mongodb postgresql the_silver_searcher zsh
gdbm ncurses python tig zsh-completions
heroku node python@2 tree
heroku-node openssl readline xz
icu4c pcre sqlite yarn
If you install
mongodb via Homebrew and you already have it installed, you should get a message like this:
To reinstall 4.0.3_1, run `brew reinstall mongodb`
MongoDB is Running, now what?
So you have MongoDB running but maybe you’re not really sure if it’s working and you’re a long way away from setting up any type of integration with your project. An easy way to verify that MongoDB is working is to use the MongoDB Shell. The MongoDB Shell only works while the MongoDB Daemon is running, so you must have started it with the
mongod command. Once the daemon is running though, you can run the following command to get into the shell:
If you enter the shell you’ll get a shell prompt that looks something like this:
Then you can run this command to just see a list of the databases in MongoDB:
At this point when you’re in the MongoDB shell you can create databases, collections, and documents. Feel free to explore!
We’ve covered how to run MongoDB on Mac. We showed you how to run it if it’s already installed as well as how to install it via Homebrew and then run it. We also showed you how to check if it’s already installed and how to get into the MongoDB shell if you want to interact with it.
If you’d like experts to manage your data and don’t want to deal with the complexity of a production environment then don’t hesitate to reach out to Object Rocket to discuss your options.