Listing Databases

The most basic command for listing the databases in the MongoDB shell is ‘show dbs‘. This command prints the list of databases and their sizes. On the other hand, we need to understand that MongoDB has only databases that have data. Empty databases will never show in the output.

show dbs

Output:

Databases

Explanation: As we have seen in the image that we have List of all the databases which we had created.

How to List all Databases in the Mongo Shell?

MongoDB is a popular NoSQL database that allows for flexible and scalable data storage. When working with MongoDB, it’s essential to understand how to list all databases to manage them effectively. By using commands such as show dbs and db.stats(), users can gain insights into their database environment, including database sizes and collection counts.

In this article, We will explores the steps involved in listing all databases in MongoDB and interpreting the output and so on.

Similar Reads

How to show the Entire Database in MongoDB?

Managing databases in MongoDB requires an understanding of how to list all databases. This fundamental task allows users to view existing databases and their sizes, providing insight into the overall database environment....

1. Create Database

First, let’s create some databases using Mongo shell....

2. Listing Databases

The most basic command for listing the databases in the MongoDB shell is ‘show dbs‘. This command prints the list of databases and their sizes. On the other hand, we need to understand that MongoDB has only databases that have data. Empty databases will never show in the output....

3. Interpreting the Output

After executing `show dbs`, MongoDB prints out a list of the databases in our system with the sizes of each database in megabytes (MB). Big data is usually associated with larger databases that facilitate increased data storage and usage. However, size isn’t the only reflection of the complexities and the performance of our MongoDB environment....

4. Detailed Database Information

While show dbs gives a brief but useful outline, you can drill down into specific databases by using db.stats() function. This command displays the categories such as database size, the number of collections, and document count....

5. Exploring Database Contents

Besides listing databases, it is also crucial to interpret the data inside them. Change the database environment with the use command and display all collections within the database using the show collections command. These commands permit easy navigation and control of the MongoDB databases and collections....

6. Exiting the MongoDB Shell

Once we have completed our tasks in the MongoDB shell, we can exit. Click on the close (X) button located at the top-right corner of the MongoDB Compass window....

Conclusion

Overall, Listing all databases in MongoDB is a crucial aspect of database management, providing users with valuable information about their database environment. By understanding and using commands such as show dbs and db.stats(), users can effectively manage their databases, ensuring optimal performance and scalability....