QBoard » Big Data » Big Data - Data Storage : Hive, HBase, MongoDB, Teradata.. » How can I list all collections in the MongoDB shell?

How can I list all collections in the MongoDB shell?

  • In the MongoDB shell, how do I list all collections for the current database that I'm using?
      September 6, 2021 5:58 PM IST
    0
  • To list all collections in Mongo shell, you can use the function getCollectionNames().

    The syntax is as follows −
    
    db.getCollectionNames();
    You can use another command which is collections. The syntax is as follows −
    
    show collections;
    To list all collections in Mongo, use the above two functions. The query is as follows −
    
    > db.getCollectionNames();
      November 26, 2021 12:26 PM IST
    0
  • Apart from the options suggested by other people:

    show collections  // Output every collection
    show tables
    db.getCollectionNames() // Shows all collections as a list

     

    There is also another way which can be really handy if you want to know how each of the collections was created (for example, it is a capped collection with a particular size):

    db.system.namespaces.find()
    
      September 23, 2021 1:53 PM IST
    0
  • First you need to use a database to show all collection/tables inside it.

    >show dbs
    users 0.56787GB
    test (empty)
    >db.test.help() // this will give you all the function which can be used with this db
    >use users
    >show tables //will show all the collection in the db
      October 2, 2021 2:15 PM IST
    0