Question – How do I list all the collections available in the MongoDB database?
MongoDB is a NoSQL database, that stores documents in JSON format. A collection is an entity in MongoDB (ie similar to a table in RDBMS databases) that stores JSON documents.
Advertisement
You can use one of the below options to list collections in a MongoDB database.
- Mongo Shell: You can use one of the following commands from Mongo Shell to list all available collections in the MongoDB database. Before running the below commands you must be connected with the target database using
use database_name
.show collections
show tables
db.getCollectionNames()
- Node.js: Use
listCollections()
method to list all collections in database with Node.js application. The application must have created a connection to the MongoDB database before.db.listCollections()
- JavaScript Shell: The JavaScript shell users can use the following method to list collections in the MongoDB database.
db.getCollectionNames()
Thanks, hope this quick how-to guide helps you to find all collections in a MongoDB database.