I started playing with MongoDB this weekend. It’s a cool little database, and John Nunemaker’s MongoMapper gem is a treat.
Mongo’s maintainers are nice enough to provide pre-compiled binaries for OS X, but you still have to do a little setup and configuration. (There’s actually a portfile on MacPorts, but it wasn’t up-to-date with the latest version when I found it.)
Here’s how I got the server installed and running as a daemon in OS X, for local development.
Download, unpack, and install the pre-compiled 64-bit binaries:
(If you’re on a 32-bit machine, substitute in
i386 for each
Next, you’ll want to make a config file so you can change the server’s options without fiddling with command-line arguments.
Now, we’ll make a
launchd job to register the server as an OS X daemon.
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.
Now we just need to load the
sudo launchctl load Library/LaunchDaemons/org.mongodb.mongod.plist
And that should do it! Try visiting http://localhost:28017 to see the status console for your database.
One last thing: you should probably add
/usr/local/mongodb/bin to your
$PATH. That way you can use the other binaries that ship with MongoDB, like the
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'
Thanks to theozaurus in the comments below for that tip.