Installing and Running MongoDB on OSX Installing and Running MongoDB on OSX database database

Installing and Running MongoDB on OSX


If you have installed mongodb through homebrew then you can simply start mongodb through

brew services start mongodb

Then access the shell by

mongo

You can shut down your db by

brew services stop mongodb

You can restart your db by

brew services restart mongodb

For more options

brew info mongodb


Updated answer (9/2/2019):

Homebrew has removed mongodb formula from its core repository, see this pull request.

The new way to install mongodb using Homebrew is as follows:

~> brew tap mongodb/brew~> brew install mongodb-community

After installation you can start the mongodb service by following the caveats:

~> brew info mongodb-communitymongodb/brew/mongodb-community: stable 4.2.0High-performance, schema-free, document-oriented databasehttps://www.mongodb.com/Not installedFrom: https://github.com/mongodb/homebrew-brew/blob/master/Formula/mongodb-community.rb==> CaveatsTo have launchd start mongodb/brew/mongodb-community now and restart at login:  brew services start mongodb/brew/mongodb-communityOr, if you don't want/need a background service you can just run:  mongod --config /usr/local/etc/mongod.conf

Deprecated answer (8/27/2019):

I assume you are using Homebrew. You can see the additional information that you need using brew info $FORMULA

~> brew info mongo                                                           255mongodb: stable 2.4.6, devel 2.5.1http://www.mongodb.org//usr/local/Cellar/mongodb/2.4.5-x86_64 (20 files, 287M) *  Built from sourceFrom: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb==> CaveatsTo reload mongodb after an upgrade:    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Caveats is what you need to follow after installation.


Assuming you have created the data/db directory under bin after install.

  1. Start a terminal for your mongo server
  2. Go to <mongodb-install-directory>/bin directory
  3. Run the command

    ./mongod

  4. Start a terminal for your mongo shell

  5. Go to <mongodb-install-directory>/bin directory
  6. Run the command (make sure you put the name of the database)

    ./mongo test