
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to list all users in the Mongo shell?
In order to list all users in the Mongo shell, use the getUsers() method or show command.
Case 1 − Using getUsers()
The syntax is as follows −
db.getUsers();
Case 2 − Using show command
The syntax is as follows −
show users;
Let us implement both the syntaxes in order to list all users in the Mongo shell.
Case 1 − The first query is as follows −
> db.getUsers();
The following is the output −
[ { "_id" : "test.John", "user" : "John", "db" : "test", "roles" : [ { "role" : "readWrite", "db" : "test" }, { "role" : "dbAdmin", "db" : "test" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }, { "_id" : "test.admin", "user" : "admin", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] } ]
Case 2 − The second query is as follows −
> show users;
The following is the output −
{ "_id" : "test.John", "user" : "John", "db" : "test", "roles" : [ { "role" : "readWrite", "db" : "test" }, { "role" : "dbAdmin", "db" : "test" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] } { "_id" : "test.admin", "user" : "admin", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
- Related Articles
- How to list all collections in the Mongo shell?
- How to list all databases in the Mongo shell?
- How to list all users in a Linux group?
- Inserting Date() in MongoDB through Mongo shell?
- How to list all users who are currently logged into the Linux system?\n
- List logged-in MySQL users?
- How to Create a Shared Directory for All Users in Linux?
- Does Mongo shell treats numbers as float by default.? How can we work it around explicitly?
- How to delete all users from specific OU using PowerShell?
- How to operate on all databases from the MongoDB shell?
- How to merge array of documents in Mongo DB?
- How to Use lua-mongo library in Lua Programming?
- SQL Server Query to Find All Permissions/Access for All Users in a Database
- Checking create time for all users in SAP HANA
- How To List All Group in Linux ?

Advertisements