Auto Logout current user when using db.auth

Hello, everyone !!!

I’m trying to learn MongoDB for myself. But I have an issue with command db.auth.
I login to mongodb server and following these command:

mongosh -u max -p max --authenticationDatabase admin

use shop

db.createUser({user:"john", pwd:"john", roles:["readWrite"]})

db.auth('john', 'john')

// Check current user
db.runCommand({ connectionStatus: 1 })

Mongodb auto logout my current user ‘max’, and authentication with ‘john’. I think it’s bug.
I’m using Mongodb Community 7.0

Hi @tai_vu and welcome to the community!
This should be the way to be able to switch users:

“IMPORTANT
It is not possible to switch between users in the same mongosh session. Authenticating as a different user means the session has the privileges of both authenticated users. To switch between users exit and relaunch mongosh.”
https://www.mongodb.com/docs/manual/tutorial/authenticate-a-user/#:~:text=IMPORTANT,relaunch%20mongosh.

Has access control been enabled correctly?
Which is the exact version of mongo?

So tomorrow I will also carry out verifications!

Regards

1 Like