Question

I want to use Paul Melnikow's Objective-C library (https://github.com/paulmelnikow/ObjCMongoDB) in an iOS app to connect to a mongoDB server hosted by mongolab but I'm having trouble figuring out how to use it. I assume my standard URI has to be pasted into the code somewhere, or my user, password, host, port, etc. have to be brought in but I am not sure where.

Melnikow's library says to use the code below to establish a database connection but I don't see how my standard URI from mongolab fits into this at all.

NSError *error = nil;
MongoConnection *dbConn = [MongoConnection connectionForServer:@"127.0.0.1" error:&error];
MongoDBCollection *collection = [dbConn collectionWithName:@"mydb.cities"];
Was it helpful?

Solution

It looks like that particular library doesn't support URI connections. You'll have to just use the host and port to establish the connection, and after that then run the commands to select a database and authenticate. Mongo does authentication post-connection, unlike something like MySQL or Postgres where you need to authenticate to even connect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top