The connectionStatus command shows authenticated users (if any, among some other data):
db.runCommand({connectionStatus : 1})
Which results in something like bellow:
{
"authInfo" : {
"authenticatedUsers" : [
{
"user" : "aa",
"userSource" : "test"
}
]
},
"ok" : 1
}
So if you are connecting from the shell, this is basically the current user
You can also add the user name to prompt by overriding the prompt function in .mongorc.js file, under OS user home directory. Roughly:
prompt = function() {
user = db.runCommand({connectionStatus : 1}).authInfo.authenticatedUsers[0]
if (user) {
return "user: " + user.user + ">"
}
return ">"
}
An example:
$ mongo -u "cc" -p "dd"
MongoDB shell version: 2.4.8
connecting to: test
user: cc>db.auth("aa", "bb")
1
user: aa>