Mongosh directConnection question

Why is it possible to establish an unauthenticated mongosh directConnection to a cluster with enabled authentication?

11:32:47 mongosh:~/.mongodb/mongosh# mongosh --host pg.eng.cmp.szh.loc --port 5012 --authenticationDatabase admin
Current Mongosh Log ID: 65817f61e3a799456f978c28
Connecting to: mongodb://pg.eng.cmp.szh.loc:5012/?directConnection=true&authSource=admin&appName=mongosh+2.1.1
Using MongoDB: 6.0.9-7
Using Mongosh: 2.1.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

rs0 [direct: primary] test> db.runCommand({ usersInfo: 1 })
MongoServerError: command usersInfo requires authentication
rs0 [direct: primary] test>

I thought that a username and password must always be provided as soon as authentication is activated.

I could not find any documentation entry about this behavior.

It appears that your connection does require authentication

let me refine my question.

I did not provide a username and password with my mongodb directConnection connection string. the connection was established and I did not get any error message immediately. I got an error message in following when I tried to execute an action which requires authentication.

when I don’t provide a username and password with a postgres connection string the connection is not even established. the only thing I get is an error message immediately.

why is it possible to establish a connection / login to mongodb even if I provide no username and password and authentication is enabled in mongodb?

I found the answer:

https://groups.google.com/g/mongodb-user/c/LX4VQKDg0ms

“works as designed”.

seems that mongodb is a bit strange here.

1 Like