Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 900
naXa Avatar asked Sep 15 '15 09:09

naXa


People also ask

Where are users stored MongoDB?

For users created in MongoDB, MongoDB stores all user information, including name , password , and the user's authentication database , in the system. users collection in the admin database. Do not modify this collection directly. To manage users, use the designated user management commands.

How do I show all collections in MongoDB shell?

To list all collections in Mongo shell, you can use the function getCollectionNames().

How do I see everything in MongoDB?

To get stats about MongoDB server, type the command db. stats() in MongoDB client. This will show the database name, number of collection and documents in the database.

How do I see how many connections I have in MongoDB?

We can get the information explicitly about the number of connections made to the server by running the command db. serverStatus(). connections from any of the MongoDB Shell connected to the Server.


2 Answers

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.

like image 54
naXa Avatar answered Sep 24 '22 12:09

naXa


List belong to db users:

use db_name and db.getUsers() or show users

List according the authentication type:

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

List with the credental:

db.getUsers( {showCredentials: true,  filter: { mechanisms: "SCRAM-SHA-256" }} ) 
like image 35
Hamit YILDIRIM Avatar answered Sep 21 '22 12:09

Hamit YILDIRIM