How to List Databases and Show Collections in MongoDB
The MongoDB show collections command is the quickest way to inspect which collections exist in a database. In this article you’ll learn every method available in the MongoDB shell — show collections, db.getCollectionNames() and db.getCollectionInfos() — and how to visualise the same information as an interactive diagram.
Using the shell to show collections in MongoDB
Connect to MongoDB
Make sure MongoDB is installed on your system. Open your terminal or command prompt and start the MongoDB shell by typing:
mongosh List MongoDB databases
Once connected, retrieve the list of databases with the show dbs command:
show dbs The output includes all user-created databases. Note that some entries (such as admin, config and local) are internal MongoDB databases and are not intended for application data storage.
Switch to a database
Select the database you want to inspect with the use command. Replace ecommerce with your own database name:
use ecommerce show collections — the quickest approach
Once inside a database, run show collections to list every collection it contains:
show collections 
db.getCollectionNames() — returns a JavaScript array
db.getCollectionNames() is functionally equivalent to show collections but returns the names as a JavaScript array. This makes it ideal for scripting — you can loop over the result, filter it, or pass it to another function:
db.getCollectionNames() 
Example output: [ ‘product‘, ‘coupon’, ‘customer’, ‘cart‘]
db.getCollectionInfos() — full metadata
Run the db.getCollectionInfos() command to get the full metadata.
db.getCollectionInfos() 
You can also pass a filter object to narrow the results — for example, to find only collections whose names start with coupon:
db.getCollectionInfos()({ name: /^coupon/ }) Visualise MongoDB collections with Moon Modeler
Shell commands give you a text list, but a schema design tool turns the same information into a searchable, visual data model — useful for onboarding, documentation and schema reviews.

The advantages over shell commands include greater clarity, the ability to search across fields, view validation rules, and export documentation — all without writing a single command.
Getting started with Moon Modeler is straightforward. Create a database connection:

Then click Connect and load the existing structure to reverse-engineer all collections automatically.

Learn more about reverse engineering existing MongoDB databases.
Conclusion
There are three ways to show collections in MongoDB: the quick show collections shell shorthand, db.getCollectionNames() when you need a JavaScript array for scripting, and db.getCollectionInfos() when you need full metadata including validation rules. For a visual overview of the entire database structure, Moon Modeler lets you load, diagram and document all collections without touching the shell.
How do I start the MongoDB shell?
Open your terminal or command prompt and enter the MongoDB shell by typing the command mongosh.
How do I show a list of databases in MongoDB?
Simply type show dbs in the MongoDB shell to see all databases on the connected server.
How do I show collections in a MongoDB database?
Switch to the target database with use <dbname>, then run show collections. You can also call db.getCollectionNames() for a JavaScript array or db.getCollectionInfos() for full metadata. Another option is to use a data modeling tool to display all collections as a visual data model.
What is the difference between show collections and db.getCollectionNames()?
show collections is a shell shorthand that prints collection names to the console. db.getCollectionNames() returns a JavaScript array, making it easier to loop over results in scripts. Both commands require you to be in the target database first.
Why use a data modeling tool for showing collections?
Data modeling tools like Moon Modeler let you visualise all collections as an interactive diagram. Unlike shell commands, you get search, field-level details, validation scripts, and the ability to edit, annotate and share the schema — all in one view.
How do I improve the database structure?
You can extend the structure by adding collections, embedded objects, subject areas, notes, and images to the data model. Moon Modeler also supports sub-diagrams, data flow diagrams and flowcharts, making it easy to evolve the schema over time.
