
- 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
Does MongoDB getUsers() and SHOW command fulfil the same purpose?
Both the getUsers() method and SHOW command can be used to list all users in the Mongo shell.
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
- Command to show the database currently being used in MongoDB?
- What is the purpose of the command interpreter?
- Why SHOW DBS does not show my databases in MongoDB?
- What does 'show processlist' command do in MySQL?
- Purpose of using CHANGE command in MySQL?
- What is the BSON query for the command 'show dbs' (list of databases) in MongoDB?
- MongoDB difference between show dbs and show databases?
- Show MySQL host via SQL Command?
- MongoDB profiler output: What is the “command” operation?
- Show constraints on table command in MySQL?
- Combine SELECT & SHOW command results in MySQL?
- How to stop MongoDB in a single command?
- How do I drop a MongoDB database from the command line?
- How do we print a variable at the MongoDB command prompt?
- Does the same symbol is used, for wavelength, speed and frequency?

Advertisements