naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37916

How to list all users in the mongo shell?

In the MongoDB shell, how do I list all users for the current database that I'm using?
I can't seem to find it anywhere on stackoverflow.

Upvotes: 52

Views: 139345

Answers (4)

ranjeet jha
ranjeet jha

Reputation: 11

Following command can be used to get lis of user on a selected database.

By using find on a selected db

use admin;
db.system.users.find({}, {"user": 1, "db": 1, "roles": 1});

To Get all the user on all the db

db.getUsers();

or 

show users; 

here you can get only user, db and roles nodes in response JSON.

Upvotes: 1

Hamit YILDIRIM
Hamit YILDIRIM

Reputation: 4539

List belongs to DB users:

use db_name and db.getUsers() or show users

List according to the authentication type:

db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })

List with the credentials:

db.getUsers( {showCredentials: true,  filter: { mechanisms: "SCRAM-SHA-256" }} )

Upvotes: 5

Pratheep
Pratheep

Reputation: 91

If you like to list only user names and leave all other bulk info.. try

db.system.users.find({}, {"_id" : 1})

Upvotes: 4

naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37916

You can do:

db.getUsers()

or

show users

The both commands print a list of users for the current database. See MongoDB documentation for User Management.

Upvotes: 94

Related Questions