1

I'm trying to connect to a local MongoDB with authentication but failing.

DBClientConnection c;
string errMsg;
c.connect("localhost");
bool success = c.auth("ss1", "admin", "password", errMsg);

auth() returns always false, and the errMsg is { ok: 0.0, errmsg: "auth failed", code: 18 }

  • Without authentication, I can read and write to the DB form the code
  • Couldn't find any documentation about the response
Ran P
  • 332
  • 2
  • 4
  • 11
  • can you authenticate using the command line `mongo` application using the same credentials? – Alan Birtles Jun 07 '18 at 16:32
  • 2
    You appear to be using the legacy v1 driver methods. Is there some reason why? The legacy driver only supports MONGODB-CR for authentication, where modern releases want SCRAM-SHA1. Even downgrading on servers is no longer supported from MongoDB 4.0 and all support is being removed completely. You probably want the newer cxx driver implementation unless you are specifically locking your self in to older "unsupported" server versions intentionally. – Neil Lunn Jun 08 '18 at 02:10
  • 1
    +1 to the above - the legacy driver is end-of-life. Please do whatever it takes to upgrade to the new mongocxx driver. – acm Jun 09 '18 at 20:54

1 Answers1

1

Neil Lunn and acm were right. Using the newer version did solve the authentication issue. Thank you

Ran P
  • 332
  • 2
  • 4
  • 11