C++ driver failing to connect as user admin

395 views
Skip to first unread message

Jeff Abrahamson

unread,
Nov 16, 2017, 12:54:42 PM11/16/17
to mongodb-user
I'm using the C++ (releases/stable as of this morning) driver.  I write this:

    mongocxx::instance instance{};
    mongocxx::uri uri("mongodb://my_user:password@localhost:27017/?ssl=true");

    mongocxx::options::client client_options;
    mongocxx::options::ssl ssl_options;
    ssl_options.allow_invalid_certificates(true);
    client_options.ssl_opts(ssl_options);
    mongocxx::client client(uri, client_options);
    mongocxx::database db = client["my_database"];

    mongocxx::collection spines = db["spines"];

    {
        mongocxx::cursor cursor = spines.find(document{} << finalize);
        cout << "This happens." << endl;
        for (auto doc : cursor) {
            cout << "This doesn't happen." << endl;
            cout << bsoncxx::to_json(doc) << endl;
        }
    }


Somewhere between the two comments ("this happens" and "this doesn't happen"), the program crashes with this message:

terminate called after throwing an instance of 'mongocxx::v_noabi::query_exception'
  what():  auth failed: generic server error
Aborted (core dumped)


and the mongo log shows this:

2017-11-16T17:51:34.957+0000 [initandlisten] connection accepted from 1.2.3.4:42196 #1430800 (27 connections now open)
2017-11-16T17:51:35.420+0000 [conn1430800]  authenticate db: admin { authenticate: 1, user: "my_user", nonce: "xxx", key: "xxx" }
2017-11-16T17:51:35.421+0000 [conn1430800] Failed to authenticate my_database@admin with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user my_database@admin
2017-11-16T17:51:35.528+0000 [conn1430800] end connection 1.2.3.4:42196 (26 connections now open)


Those credentials work from the commandline client.

I'm pretty confused why I'm seeing this error about admin.  Anyone see what I'm missing?

Jeff Abrahamson

unread,
Nov 16, 2017, 1:56:49 PM11/16/17
to mongodb-user
Answer is to include the database in the uri string as well:

    mongocxx::uri uri("mongodb://my_user:password@localhost:27017/my_database?ssl=true");

Jeff Abrahamson
https://www.p27.eu/jeff/

Andrew Morrow

unread,
Nov 16, 2017, 2:07:44 PM11/16/17
to mongod...@googlegroups.com

Hi Jeff -

I'm happy to hear that you got it working. Also, please be aware that we anticipate issuing the MongoDB C++ driver 3.2.0-rc0 release very shortly, so that releases/stable branch will include some new features soon.

Thanks,
Andrew


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/7a237a9c-67b0-418c-b3e2-57d7e3c75d38%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages