List all Databases in MongoDB Shell
How to List all Databases in the MongoDB Shell?
To list all databases in MongoDB, you can use the show dbs command in the MongoDB shell. This command displays the names and sizes of all databases on the server. It's a quick way to see all databases accessible in your MongoDB environment.
Description:
In MongoDB, you can list all databases by running show dbs in the MongoDB shell. This command provides a list of databases along with their storage sizes, giving you a quick overview of available databases in your MongoDB instance.
Syntax:
To list all databases, enter the following command in the MongoDB shell:
show dbs
Example:
Assuming you are in the MongoDB shell:
Code:
// List all databases
show dbs
Explanation:
- show dbs
- This command lists each database along with its size on disk.
- The command does not require any parameters or additional configuration, making it simple to run.
When you run show dbs, the output includes:
- The name of each database.
- The storage size used by each database (in bytes).
Note: Only databases with allocated storage space appear in the list. Empty databases (databases with no collections or data) won’t be shown until they contain at least one collection.
Example Output:
admin 41.28 KiB config 12.00 KiB local 12.00 KiB mydb 45.00 KiB
This output shows the names of each database and their respective storage sizes.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/mongodb/snippets/how-to-list-all-databases-in-the-mongodb-shell.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics