2

I have a mongDB running in my VM (Ubuntu) in access control mode. I created an admin user with this role:

    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]

I installed the mongoDB driver for C++ and wrote a mini-program to test it. My code (basically copied from mongocxx tutorial):

  mongocxx::instance instance{};
  mongocxx::uri uri(
      "mongodb://userName:password@localhost:27017/?authSource=admin");
  mongocxx::client conn(uri);

  mongocxx::database db = conn["test"];   
  mongocxx::collection coll = db["test"];

  mongocxx::cursor cursor = coll.find({});
  for (auto doc : cursor) {
    std::cout << bsoncxx::to_json(doc) << "\n";
  }

I inserted a document in test.test from mongo shell. The 'find' command works with the same user in mongo shell. When running this mini program I get:

terminate called after throwing an instance of 'mongocxx::v_noabi::query_exception'
what():  could not start SASLPrep for password: generic server error
Aborted (core dumped)

When I cancel the MonogDB access control and connect to it with the same lines but without the user/password it works great and I can insert and find documents. How to fix this?

Richárd Baldauf
  • 1,068
  • 2
  • 10
  • 24

0 Answers0