Senger CodeLab 🚀

How to list all databases in the mongo shell

September 29, 2026

📂 Categories: Mongodb
How to list all databases in the mongo shell

Navigating the vast landscape of data within MongoDB can feel like exploring an uncharted territory. One of the first landmarks you’ll want to identify is a comprehensive list of your databases. Knowing how to list all databases in the mongo shell is fundamental for any MongoDB user, whether you’re a seasoned administrator or just starting your NoSQL journey. This seemingly simple task unlocks access to your data collections and empowers you to manage your MongoDB environment effectively. This guide will provide a clear, step-by-step approach to listing databases in the mongo shell, equipping you with the knowledge to navigate your data world with confidence.

Connecting to Your MongoDB Instance

Before you can list your databases, you need to establish a connection to your MongoDB instance. This involves using the mongo shell, a powerful command-line interface for interacting with MongoDB. The connection process varies slightly depending on your setup, but the general syntax is as follows:

mongo --host <hostname> --port <port> -u <username> -p <password>

Replace <hostname>, <port>, <username>, and <password> with your specific credentials. If you’re running MongoDB locally with default settings, you can often simply use mongo.

The Magic Command: show dbs

Once connected, the command to list all databases is remarkably simple: show dbs. Executing this command in the mongo shell will display a list of all databases in your MongoDB instance, along with their respective sizes. This provides a quick overview of your data landscape, allowing you to easily identify the databases you need to work with.

For instance, if you have databases named “mydatabase” and “test,” the output would look similar to this:

admin 0.000GB<br></br> config 0.000GB<br></br> local 0.000GB<br></br> mydatabase 0.078GB<br></br> test 0.000GB

This clearly shows the size of each database, providing valuable insights into your data storage utilization.

Understanding the Output of show dbs

It’s important to note that show dbs only displays databases that contain collections with data. Empty databases won’t appear in the list. This ensures that the output remains concise and relevant, focusing only on databases that are actively storing information. Furthermore, the sizes displayed are approximations and may not be entirely precise.

Consider a scenario where you create a new database but haven’t added any collections or documents to it. Using show dbs won’t immediately reveal this newly created database. It will only appear after you insert some data into a collection within that database.

Alternative Approaches and Further Exploration

While show dbs is the most common method, there are alternative approaches to list databases, such as using the db.adminCommand('listDatabases') command. This provides a more detailed JSON output including information like database names, sizes, and whether they are empty. This can be particularly useful for scripting and automation tasks.

For a deeper understanding of MongoDB administration and data management, explore resources like the official MongoDB documentation and various online tutorials. This will equip you with the knowledge to manage your databases efficiently and effectively.

  • Always connect to your MongoDB instance before listing databases.
  • Remember that show dbs only lists databases containing data.
  1. Connect to your MongoDB instance.
  2. Type show dbs in the mongo shell.
  3. Review the list of databases and their sizes.

Want to learn more about database management best practices? Check out this helpful resource.

External Resources:

Featured Snippet: To quickly list all databases in the mongo shell, simply connect to your MongoDB instance and execute the command show dbs. This will display a list of all databases containing data, along with their approximate sizes.

[Infographic Placeholder]

FAQ

Q: Why isn’t my newly created database showing up when I use show dbs?

A: Newly created databases only appear after you’ve added data to a collection within them. show dbs only displays databases that contain data.

Mastering the art of listing databases in the mongo shell is a crucial first step in effectively managing your MongoDB environment. By understanding the nuances of the show dbs command and exploring alternative approaches, you can gain valuable insights into your data landscape and navigate your collections with ease. Start exploring your data world today, and unlock the full potential of MongoDB. Dive deeper into MongoDB management by exploring the linked resources and continue your journey to becoming a MongoDB expert. Consider experimenting with different commands and techniques to further enhance your understanding and proficiency.

Question & Answer :
I know how to list all collections in a particular database, but how do I list all available databases in MongoDB shell?

Listing all the databases in mongoDB console is using the command show dbs.

For more information on mongo shell commands, refer the MongoDB Shell (mongosh) documentation.