Stephen Steneker edited this page Aug 5, 2014 · 18 revisions

Getting started using ObjCMongoDB in your MacOS project


There are several ways to use this library in your MacOS project.

  1. Add the files directly to your project and build it as part of your own target.
  2. Use the included Xcode project to build ObjCMongoDB.framework and link against that. You can either embed the framework in your application or install it separately. If you only need BSON encoding and decoding but don't need to connect to a MongoDB server, you can use BSON.framework instead.
  3. [Install ObjCMongoDB via CocoaPods](Installing via CocoaPods)

The rest of this document explains the first option: adding the files to your own project.

Step 1

Use source control to check out the latest tagged release of the project, updating the submodule. The submodule is the the 10gen Mongo C Driver, the library's main dependency. You may need to run git submodule update --init and/or git submodule sync to clone the submodule.

The other dependency comes with the project: a slightly modified version of Matthew Gallagher's OrderedDictionary, a subclass of NSMutableDictionary which preserves the order of its keys. It's required for the Mongo part of the library and recommended for the BSON part. If you want your keys kept in order when you encode documents, you'll want to use it in your own code.

Step 2

Copy the folder containing the 10gen Mongo C Driver source code to your project folder, if it's not already there:

  • mongo-c-driver/src

In Project Navigator, Create a new Group in your project called ObjCMongoDB and select it. Then add the above folder to your project, but do not add it to your target yet. That creates a new group called src. Rename it to mongo-c-driver.

If all you need is BSON encoding and decoding, select following files:

  • bson.c
  • encoding.c
  • numbers.c

If you need BSON and Mongo, select following files

  • bson.c
  • encoding.c
  • numbers.c
  • mongo.c
  • md5.c
  • env.c

then open file inspector and make checked in Target membership tab(remember that when you added src into your project, you unchecked add to target so they are not associated with your project).

Step 3

Add to your project – and target – the folders containing ObjCMongoDB's classes. When you do this, select Create Groups for any added folders.

If all you need is BSON encoding:

  • BSON
  • OrderedDictionary (optional, but recommended)

And if you need BSON and Mongo:

  • BSON
  • Mongo
  • OrderedDictionary

Step 4

Add CoreData.framework to linked frameworks.

Automatic Reference Counting (ARC)

The entire project works with either ARC or manual retain–release.


If you have questions about ObjCMongoDB, consider posting on Stack Overflow. You can also contact the author through his GitHub profile.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.