Mongocxx driver Uri with user authentication problem

309 views
Skip to first unread message

cpalum...@gmail.com

unread,
Sep 4, 2018, 6:05:17 PM9/4/18
to mongodb-user
I'm having an authentication issue.
Based on the configure mongocxx driver page I modified the Uri to read "mongodb://localhost:27017/&user:userpwd/&authSource=admin" .

Although it starts up fine I doesn't seem to allow me to use the privileges assigned to the user role (same error as attempting a query with and unauthorized user).

Can anyone help me out with this? I'm not sure if the Uri is correct or the error is caused by my user and role assigned to it.

Thanks for any help or direction on this.

Wan Bachtiar

unread,
Sep 4, 2018, 8:37:31 PM9/4/18
to mongodb-user

Based on the configure mongocxx driver page I modified the Uri to read “mongodb://localhost:27017/&user:userpwd/&authSource=admin” .

Hi,

Are you referring to mongo-cxx-driver: configuration page ?

The username and password should go before the hosts value, for example:

auto client = mongocxx::client{uri{"mongodb://username:password@localhost:27017/?authSource=databaseName"}};

Which follows the format of MongoDB Connection String URI.

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

If you still have futher questions, could you provide:

  • mongocxx version
  • MongoDB server version
  • Code snippet on how you’re constructing mongocxx::uri

Regards,
Wan.

cpalum...@gmail.com

unread,
Sep 10, 2018, 12:46:28 PM9/10/18
to mongodb-user
Thanks a lot Wan. Been scratching my head on that for a while.
Reply all
Reply to author
Forward
0 new messages