Start MongoDB Mac - How to Start MongoDB on a Mac

Introduction

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:

> mongod

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:

2019-06-27T09:04:38.600-0500 I NETWORK  [initandlisten] waiting for connections on port 27017

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:

$ brew install mongodb

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:

$ mongod

Do I Already Have MongoDB Installed?

If you’re not sure if you already have it installed you can run the command:

$ which mongo

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:

/usr/local/bin/mongo

You can also check if it’s been installed through Homebrew by using this command to see what’s been installed via Homebrew:

$ brew list

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.

$ brew list
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:

Warning: mongodb 4.0.3_1 is already installed and up-to-date
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:

$ mongo

If you enter the shell you’ll get a shell prompt that looks something like this:

anonymous:demoDatabase >

Then you can run this command to just see a list of the databases in MongoDB:

> show dbs
admin             0.000GB
config            0.000GB
local             0.000GB
test              0.000GB

At this point when you’re in the MongoDB shell you can create databases, collections, and documents. Feel free to explore!

Conclusion

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.

Pilot the ObjectRocket platform free for 30 Days

It's easy to get started. Imagine the time you'll save by not worrying about database management. Let's do this!

PILOT FREE FOR 30 DAYS

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.