Utilizing db.getCollectionNames()
Another method we can use is db.getCollectionNames(), which returns an array of collection names in the current database.
By running this command, we receive an array containing the names of all collections present in the database we’re currently connected to.
Example
We retrieved an array of collection names in the current database using db.getCollectionNames(), providing us with a quick overview of available collections.
db.getCollectionNames()
Output:
How to List All Collections in the MongoDB Shell?
Managing collections is a fundamental task in MongoDB database administration. Knowing how to list all collections in the MongoDB shell is essential for understanding your database structure and managing your data effectively. In this article, we’ll explore how to list all collections in the MongoDB shell and discuss why this knowledge is important for database administrators and developers.