There are numerous posts, manuals and readme articles on installation of MongoDB in Mac OS X. This post documents the steps I went through to install the latest release of MongoDB on my Mac running Mountain Lion 10.8.5 & setting it up to run as a daemon. The steps outlined below closely follow the steps shared by Github user xiaolai in his repository MongoDB-OSX-Launchctl. One of the issue I faced following the steps in his readme was the a Bad file descriptor error raised by launchctl, possibly caused by a mistake I made in the paths of the directories required by MongDB.

To setup MongoDB to run as a daemon, download the latest version of MongoDB and decompress the dowloaded file –

1
2
wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz 
tar -zxvf mongodb-osx-x86_64-2.4.6.tgz 

Copy the contents of the folder mongodb-osx-x86_64-2.4.6/bin/ to /opt/local/bin. Alternatively, you can use Mac Ports or Homebrew to install MongoDB. The next steps assume MongoDB binaries are present in /opt/local/bin.

Before you setup MongoDB to run as a daemon, you will need to create a data directory, a directory where log files will be written and a configuration file. Follow the steps below –

1
2
3
sudo mkdir -p /opt/local/var/db/mongodb
sudo mkdir -p /opt/local/var/log/
sudo touch /opt/local/var/log/mongodb.log

You can provide a configuration file to MongoDB or skip the following steps. Read more about the MongoDB configuration here – http://docs.mongodb.org/manual/reference/configuration-options/. A basic MongoDB configuration file (name it mongod.conf) looks like this –

1
2
bind_ip = 127.0.0.1
journal = true

If you have created a configuration file, copy it to the appropriate directory –

1
2
sudo mkdir -p /opt/local/etc/mongodb
sudo cp mongod.conf /opt/local/etc/mongodb/

The important step in setting up MongoDB to run as a daemon in Mac OS X is to create a Plist file and use it as a launchctl item. Create a file called org.mongo.mongod.plist with the following contents –

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.mongo.mongod</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/local/bin/mongod</string>
        <string>--dbpath</string>
        <string>/opt/local/var/db/mongodb</string>
        <string>--logpath</string>
        <string>/opt/local/var/log/mongodb.log</string>
        <string>--config</string>
        <string>/opt/local/etc/mongodb/mongod.conf</string>     
    </array>
</dict>
</plist>

Note that the path to the mongod and the directories created earlier should be correctly specified in the Plist file. Any errors in these program arguments result in errors.

Install the launchctl item like so –

1
2
3
4
sudo cp org.mongo.mongod.plist /Library/LaunchDaemons/.
sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
sudo launchctl start org.mongo.mongod

Note that launchctl can be setup to run MongoDB with a Plist in /System/Library/LaunchDaemons, however, in my case, /Library/LaunchDaemons worked without any issues. With the release of OS X Mavericks in the horizon, I may need to update the post with any changes in the steps above.

If you are using the Google Analytics for iOS SDK v3.0 in your iOS app, it is likely that you will encounter linker errors after following the steps in the developer guide. Here is a snippet of the linker error I encoutered today –

1
2
3
4
5
6
7
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_ASIdentifierManager", referenced from:
objc-class-ref in libGoogleAnalyticsServices.a(TAGAdvertiserId.o)
      objc-class-ref in libGoogleAnalyticsServices.a(TAGAdvertisingTrackingEnabledMacro.o)
      objc-class-ref in libGoogleAnalyticsServices.a(TAGMobileAdwordsUniqueIdMacro.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The developer guide doesn’t tell you to add AdSupport.framework in your project’s build phases. Once AdSupport.framework is added in your project, the linker errors go away.

I started a blog with Wordpress five years ago with the idea of sharing my travels as a developer, geek, technologist, etc. The blog has had more than 50,000 visits over the last five years, if you are one of them reading this post, thank you for visiting my blog.

After five years of using Wordpress as the blog engine and Akismet for keeping the spammers away, I wanted to try Octopress after seeing all the cool blogs using it and Github Pages to host themselves. For programmers/developer/hackers who are always near a Mac or a PC, Octopress provides a lot of power in the hands of the author. Two commands below are enough to publish a blog post –

1
2
$ rake generate
$ rake deploy

The only drawback I see with this workflow is the risk of publishing a post that is not yet ready for general consumption. For now, I have modified the Rakefile to include a line with published: false in the new_post template.

In the next post, I will be listing a bunch of links to resources I found very useful in setting up this blog. I hope with this new blogging platform, I should be able to post more frequently than I have in the last five years.