Skip to content

How to list all collections in MongoDB database

Category
Databases
Covers
MongoDB, Node.js

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.

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.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top