4

Full Disclosure:

I'm not an educated programmer, and the entirety of my programming experience is in Javascript and Objective-C.

So now you know what you're dealing with. Tread carefully. No sudden moves.


I'm writing an iPad app which talks to a Mac server. I'd like to use MongoDB for the backend, and ObjCMongoDB looks like the perfect fit, but I can't get it to work using the instructions here:

https://github.com/noa--/ObjCMongoDB/wiki/GettingStarted

My repro steps:

  1. From the main ObjCMongoDB page on gitHub, click "Clone in Mac" (I'm using GitHub for Mac to handle the download)

  2. From the command line, navigate to the ObjCMongoDB directory and type:

    git submodule update
    
  3. Then:

    git checkout v0.9.6
    
  4. copy the mongo-c-driver/src folder into the XCode Project folder

  5. In XCode, make a new group in the Project called "ObjCMongoDB" and select it

  6. Add the src folder from step 4 to the Project, but not to the target.

  7. Change the name of src in the Project to mongo-c-driver

  8. Add these files in mongo-c-driver to the target:

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

  9. In XCode, select the ObjCMongoDB group again, and add to both the project and the target the following folders, checking "Create groups for any added folders":

    • ObjCMongoDB/BSON
    • ObjCMongoDB/Mongo
    • ObjCMongoDB/OrderedDictionary

According to the step-by-step guide, I should be able to build & run my project now, but there are errors.

  • First, from MongoConnection+Diagnostics.h:

    #import <ObjCMongoDB/ObjCMongoDB.h>
    

    I don't have a Framework called ObjCMongoDB at this point, so this will obviously fail.

  • Even more confusing is this nifty error, followed by the API in question:

    int bson_init_finished_data( bson *b, char *data, bson_bool_t ownsData ) {
        _bson_zero( b );
        b->data = data;
        b->dataSize = bson_finished_data_size( data );
        b->ownsData = ownsData;
        b->finished = 1;
        return BSON_OK;
    }
    

    Certainly seems to expect 3 arguments...


So I'm at a loss. Any help would be greatly appreciated.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
  • To fix the first problem, change the `#import` line in MongoConnection+Diagnostics.h to `#import "ObjCMongoDB.h"`. (That's been fixed in master, subsequent to the last release.) – paulmelnikow May 09 '13 at 17:13
  • Thanks! That's actually the one thing I've already done, but since it's still broken I decided not to assume that was necessarily a positive step. – grilchgristle May 09 '13 at 17:19
  • Also, fixing the import exposes another "too few arguments" bug, this time in _MongoDBCollection.m:_ `- (BOOL) ensureIndex:(MongoMutableIndex *) index error:(NSError * __autoreleasing *) error` – grilchgristle May 09 '13 at 17:22

1 Answers1

1

I'm the author of ObjCMongoDB. Thanks for your interest in the library and the heads-up about your question.

To fix the first problem, change the #import line in MongoConnection+Diagnostics.h to #import "ObjCMongoDB.h". (That's been fixed in master, subsequent to the last release.)

The other problem is happening because v0.9.6 is based on an earlier version of the Mongo C driver than the files you're using, which I'm guessing you downloaded or cloned yourself from the 10gen repository on Github.

The C driver is set up as a submodule, so when you clone ObjCMongoDB you should see an empty mongo-c-driver folder.

From your repository root, you can run this command:

git submodule update --init

which should load the correct version of Mongo C driver (my fork as of v0.9.6, but the next release will use the official version). I'm adding a note to the readme about this step.

Once you add those versions of the .[ch] files to your project instead, it should build correctly.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
  • ok @noa, after `git checkout v0.9.6` and `git submodule update --init` I get the following: _fatal: reference is not a tree: 27182a0bf9684350e9307b6f785647dddb1c3c62 Unable to checkout '27182a0bf9684350e9307b6f785647dddb1c3c62' in submodule path 'mongo-c-driver'_ – grilchgristle May 09 '13 at 17:53
  • 1
    What does your `.gitmodules` say? Try `git submodule sync`? – paulmelnikow May 09 '13 at 18:02
  • 1
    `git submodule sync` did it! I'm off to see the wizard. Thanks a ton, @noa. – grilchgristle May 09 '13 at 18:12