Question: I jump around on various Mongodb databases and want to create a process to programatically check the Current USER. What is the MongoDB command to check the current user?
Answer:
Adding the connectionStatus details will give you formation about the current connection, specifically the state of authenticated users and their available permissions.
db.runCommand({connectionStatus : 1})
If you want to return extra information about the privileges , you can add the showPrivileges parameter, which will list out all the user privileges.
db.runCommand({connectionStatus : 1,showPrivileges:true})
Read more about MongoDB
Quick Access To Mongodb Commands Cheat Sheet -