How to display current user in MongoDB

18 May,2021 by Jack Vamvas

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 -

 


Author: Jack Vamvas (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to display current user in MongoDB


dba-ninja.com