I try to check if a user has access rights to a database or not. I use the C++ API. Previous to version 3.0, i used the auth() function on a ScopedDBConnection. This function is no more available, so my workaround would be to use run_command() and try to provide a authentication command. But i can't figure out how it should look like, i tried the following layouts:
{ authenticate: 1, user: "foo", pwd: "bar" }
{ authenticate: { user: "foo", pwd: "bar" } }
{ authenticate: 1, user: "foo", password: "bar", source: "admin" }
{ authenticate: { user: "foo", password: "bar", source: "admin" } }
{ authenticate: 1, user: "foo", password: "bar", src: "admin" }
{ authenticate: { user: "foo", pwd: "bar", src: "admin" } }
None of those commans works, there is always an error message saying "field missing/wrong type in received authenticate command".
How does a "real" authentication command look like?!
I found the following document, but still could not authenticate via run command
https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#id45This
https://docs.mongodb.com/manual/reference/method/db.auth/#db.auth and this document
https://docs.mongodb.com/manual/reference/command/authenticate/#dbcmd.authenticate don't provide the necessary information.