18 May,2021 by Rambler
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: The db.runCommand() method will return the current authenticated User, authenticated Role & some time related details
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 -
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |