Da Fish in Sea

These are the voyages of Captain Observant

Setting Up MongoDB on Mac OS X (Snow Leopard)

| Comments

Just wanted to take note of how I did this, in case it helps anyone, or if I forget :)

HomeBrew

First I installed Homebrew, as I’m kind of sick of MacPorts and Fink (specifically how slow and out of date they tend to be). This was a matter of clicking on the ‘install homebrew today’ button, which linked me to their github page… where I found the following instructions.

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

So as it turns out this did not work, and instead I got an error message about ca certs. Fortunately it did mention that I should add the -k option to turn to turn off strict cert checking. so I did this instead:

/usr/bin/ruby -e "$(curl -fsSLk https://raw.github.com/gist/323731)"

And it worked.

MongoDB

So I went over to the MongoDB site and specifically their Quickstart OS X page. Since I have homebrew now I did,

    brew update
    brew install mongodb

note that I did not need to use ‘sudo’ before either of these commands, which is nice. After installing, it instucted me to issue the following commands:

    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mongodb/2.0.0-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Which I dutifully did. Note that the ‘launchctl load …’ command actually starts the ‘mongod’ database daemon, so there’s no need to start it manually. Simply typing ‘mongo’ starts the mongodb shell

    >: mongo
    MongoDB shell version: 2.0.0
    connecting to: test

Note that >: is my prompt, in case you’ve seen Lost you may get the joke :) Now I can create a ‘collection’ by saving an item to one, like so:

    > db.foo.save({a:1})

And I can query all the items of ‘foo’ like so:

    > db.foo.find()
    { "_id" : ObjectId("4e6ffd8928d02c8f55a09dbb"), "a" : 1 }

I’ve just got started with MongoDB, but I have to say it looks like it will be really nice to work with on personal projects. No more fussing around with database schemas! Yay!

Oh, yeah, to quit mongo, you just type:

 > quit()