61 posts / categories / feed

MongoDB Installation on Mac OS X

Written in C++, MongoDB (from “humongous”) is a scalable, high-performance, open source, document-oriented database.

Here is how to setup my MongoDB on my MBP for staging a local development. I downloaded the latest 1.6.3 version.

  1. Downloaded a copy of MongoDB for Mac OS X 64 bit. Either from their website or using curl.
  2. Note:  32bit will have a limitation of up to 2.5gb of data. More info here.

    If you wish to use curl:

    curl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-1.6.3.tgz
    tar xzf mongodb-osx-x86_64-1.6.3.tgz

    And continue with the following:

    sudo mv mongodb-osx-x86_64-1.6.3 /usr/local/mongodb
    sudo mkdir /usr/local/mongodb_data /var/log/mongodb
    sudo chown -R root /usr/local/mongodb
  3. To save the trouble of fiddling with cmd line arguments, create a config file to change server’s options.
  4. sudo vi /usr/local/mongodb/mongod.conf

    Copy and paste the following:

    # Store data alongside MongoDB instead of the default, /data/db/
    dbpath = /usr/local/mongodb_data
    # Only accept local connections
    bind_ip =
  5. Make a launchd job to register the server as an OS X daemon.
  6. launchd will start the server at startup, stop it before shutdown, make sure it stays up, and redirect its output to a nice log file.

    sudo vi /Library/LaunchDaemons/org.mongodb.mongod.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
    <plist version="1.0">
  7. Now to load the launchd job:
  8. sudo launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist
  9. Try checking the status console for your database. by running http://localhost:28017 on web browser.
  10. It will be useful to add /usr/local/mongodb/bin to your $PATH.
  11. By doing so, you can use the other binaries that ship with MongoDB, like the mongo console, mongoexport, and so on.

    You can adjust your path the regular way by editing your shell’s profile, or you can use this nice paths.d mechanism that OS X provides:

    sudo sh -c 'echo "/usr/local/mongodb/bin" > /etc/paths.d/mongodb'
  12. Finally to test run on MongoDB.
  13. On a terminal screen, ensure that mongodb is already up and running, try saving/finding some data.


The next task would be to sync up the MongoDB with my MAMP.

Reference and credit source: