Clone this wiki locally
Getting started using ObjCMongoDB in your MacOS project
There are several ways to use this library in your MacOS project.
- Add the files directly to your project and build it as part of your own target.
- Use the included Xcode project to build
ObjCMongoDB.frameworkand 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
- Install ObjCMongoDB via CocoaPods
The rest of this document explains the first option: adding the files to your own project.
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.
Copy the folder containing the 10gen Mongo C Driver source code to your project folder, if it's not already there:
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:
If you need BSON and Mongo, select following files
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).
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:
- OrderedDictionary (optional, but recommended)
And if you need BSON and Mongo:
Add CoreData.framework to linked frameworks.
Automatic Reference Counting (ARC)
The entire project works with either ARC or manual retain–release.