1

I'm very new to use ObjCMongoDB; I need to connect to a mongoDB from inside my application so I'm trying to integrate ObjCMongoDB.framework into my project.

I've read the wiki and I didn't find any reference on connecting to a DB with username and password. Maybe I didn't look into enough but the only suggested example of connection is the following:

MongoConnection *dbConn = [MongoConnection connectionForServer:@"127.0.0.1" error:&error];

with no user and no pwd.

Did anyone get into the same problem or is there a method that could be useful? I found that in mongo.c there is mongo_cmd_authenticate but I don't know how to use it.

Any suggestion is really appreciated.

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75
  • I don't think mongo has built in support for authentication. What are you really trying to do? Securely connect to a database on an external server? – Mike Mertsock Feb 28 '14 at 16:04
  • Yes, I'm trying to connect to an external server. In particula the hosting server is mongohq. I saw there that several languages like python, ruby, c# are supported. but not obj-c. – user3021640 Feb 28 '14 at 18:12
  • Did you see [this pull request](https://github.com/paulmelnikow/ObjCMongoDB/pull/4)? – Mike Mertsock Feb 28 '14 at 18:27
  • I'm seeing just now, but it looks like not coming to a positive result. – user3021640 Feb 28 '14 at 19:54
  • Thank you. Integrating the patch works for connection. But after connecting successfully with authentication I got the following error when I tried to create a collection: MONGO_WRITE_ERROR: Write with given write_concern returned an error – user3021640 Mar 07 '14 at 12:21

1 Answers1

1

As of this pull request the driver has support for authentication.

NSError *error = nil;

[connection authenticate:@"mydb" username:@"user" password:@"password" error:&error];
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114