MongoURI constructor does not pass uname/password correctly

35 views
Skip to first unread message

Sarthak

unread,
Jan 14, 2011, 2:57:30 PM1/14/11
to mongodb-user
I am using mongo-java-driver version 2.3

When i create a connection string according to the prescribed format,
mongodb://fred:foobar@localhost/, it does not parse the MongoURI
fields correctly.

For the fields to get populated correctly, i have to construct the
connection string like this.

mongodb://uname@password:<HOSTNAME:PORT>/<DB_NAME>.<COLLECTION_NAME>

also, is port used separately or should be considered part of hostname?

Brendan W. McAdams

unread,
Jan 14, 2011, 3:18:24 PM1/14/11
to mongod...@googlegroups.com
There is no 'global' username or password with MongoDB: A username is associated with a specific DB, which is why the URI format requires it.  

Port is used separately from hostname, but is optional.
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sarthak

unread,
Jan 14, 2011, 3:49:15 PM1/14/11
to mongodb-user
So if my specific db requires a uname/password, how should I do that?

Sarthak

unread,
Jan 14, 2011, 3:49:50 PM1/14/11
to mongodb-user
if my specific DB requires authentication, how do we pass that in?


On Jan 14, 12:18 pm, "Brendan W. McAdams" <bren...@10gen.com> wrote:

Brendan W. McAdams

unread,
Jan 14, 2011, 4:12:37 PM1/14/11
to mongod...@googlegroups.com
You'll need to specify the URL as 

mongodb://<user>:<password>@<hostname:port>/<db> 

The Java Driver will not automatically authenticate when you connect so you'll need to connect, and then call authenticate on the DB object, passing uriInstance.getUsername() and uriInstance.getPassword()

Sarthak

unread,
Jan 14, 2011, 4:58:31 PM1/14/11
to mongodb-user
Ok.. that suggestion helped, to authenticate after getting the DB
object..
Reply all
Reply to author
Forward
0 new messages