How Can I List All Collections In The MongoDB Shell?

Here We will discuss How can I list all collections in the MongoDB shell where there are two ways to get the important list of all the collections in the MongoDB Shell and the are get collections and show collections. Let’s understand all of them one by one.


Collections are document or group of documents which contains whole data in the case of SQL we have structured data along with schema whereas in the case of MongoDB Does not contain any of the schemas.

And to find the total how many collections are there which exist in the database we use to list all the collections using some commands

Ways To Get The List Of Collections

There are two different ways by which we can get the list of all the collections in MongoDB Shell and here we will discuss both one by one.

List Using db.getCollectionNames();

To understand it let’s follow the example given below

// The Result will be

As shown it will simply display a list of all the collections present there.

Now let’s look at the other method for the same.

show collections;
[ "ConvertStringToDateDemo", "IdUpdateDemo", "ProductsInformation", "addFieldDemo", "addNewFieldToEveryDocument", "arrayInnerElementsDemo", "arrayLengthGreaterThanOne", "arrayOfArraysDemo", "caseInsensitiveDemo", "changeDataType", "changeType", "charactersAllowedDemo", "charactersDemo", ]

The result of this command will also be the same as given by the previous one.


Learn More about java at MongoDB Tutorial and Problems and solve the problems that you face during solving the java problems also learn all the concepts of core java to keep growing.

To learn more about How Can I List All Collections In The MongoDB Shell? visit Display all MongoDB Collections

To learn more about python and other programming languages visit Tutorials for all the programming languages to grow and learn new.

Leave a Comment

%d bloggers like this: