1. Home
  2. MongoDB
  3. MongoDB Tutorial
  4. MongoDB – Show Collection

MongoDB – Show Collection

Mongodb Show Collection

Use show collections command from MongoDB shell to list all collections created in the current database. First, select the database you want to view the collection.

Mongodb Show Collection

Select your database and run show collections command to list available collections in MongoDB database.

> use mydb
> show collections

Output:

TECADMIN
accounts
mycol
pproducts
users

Get Collections Information

To find detailed information about the database collections use .getCollectionInfos() function. This will provide an array of documents with collection information, such as name and options.

> db.getCollectionInfos();

You can also use filters with the above commands, for example, to fetch the details of specific collection with their name use following command:

> db.getCollectionInfos({ name: "accounts" });

Output:

[
        {
                "name" : "accounts",
                "type" : "collection",
                "options" : {

                },
                "info" : {
                        "readOnly" : false
                },
                "idIndex" : {
                        "v" : 2,
                        "key" : {
                                "_id" : 1
                        },
                        "name" : "_id_",
                        "ns" : "mydb.accounts"
                }
        }
]
Tags , ,
Was this article helpful to you? Yes 28 No 16
Advertisement