Friday, July 8, 2011

Setting up MongoDB on OSX

Recently I successfully downloaded and installed MongoDB on my mac. I am a Windows developer dwelling in the world of linux programming, so I wanted to blog about my experience as it may be helpful to other fellow devs who are new to linux as well.

Most of the steps below are refinement / explanation of http://www.mongodb.org/display/DOCS/Building+for+OS+X
  • Step 1 - Download MongoDB server - From mongodb.org website download MongoDB server and untar the files in some folder (MongoDB_Server).
  • Step 2 - Create a folder /data/db in your root. MongoDB server uses this path to store the database(s).
  • Step 3- Download MongoDB client - From mongodb.org download a compatible client (same version as the server) and untar the files in client folder (MongoDB_Client)
  • Step 4 - If you haven't done so far, you must download package manager on OSX called homebrew. A package manager on linux is an application that makes it dead simple to download other applications and install them on your system. To download homebrew open a shell window and type: curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
  • Step 5 - Download boost C++ library - Execute: brew install boost
  • Step 6 - Download scons (Makefile executor) - Execute: brew install scons
  • Step 7 - Download pcre++ (Perl regular expression lib) - Execute: brew install pcre++
  • Step 8 - Build client - Navigate to the client folder and simply type: scons
  • Step 9 - Start server - Open a new shell window and navigate to server folder's bin subfolder and type: mangod. This should start the server !
  • Step 10 - Test client - Navigate to client folder and execute: ./clientTest (this should run a simple client test)
  • Step 11 - Write your own test: In the client folder's client/example subfolder, create a test program with code from: http://www.mongodb.org/pages/viewpage.action?pageId=133415 and name it test.cpp
  • Step 12 - Now navigate to root client folder and execute: g++ -o test client/examples/test.cpp -I mongo -L. -lmongoclient -lpthread -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt
  • Step 13: Last step should compile your code and output test binary. Simply execute this binary to verify client code ! Ensure that your server is running all this time...