Mongodb Show Collection

Mongodb Show Collection

 MongoDB Show Collection


Use the 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 the show collections command to list available collections in the 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 names and options.

> db.getCollectionInfos();

You can also use filters with the above commands, for example, to fetch the details of the specific collection with their name use the 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"
                }
        }
]
Reactions

Post a Comment

0 Comments

close