Skip to main content

How to list all collections in the MongoDB

MongoDB is my favorite database here everything go smoothly and fast response. MongoDB has provided a lot of function support to their system. One of the is getCollectionNames() using this function we can get the list of collections.

getCollectionNames() Function use to list all collection in MongoDB. Following query, we can use in JS(Shell), Node.JS

Syntax
db. getCollectionNames()

It will return all the collection from db.

Example
db.getCollectionNames()

Output
[ "collection1", "collection2", "system.indexes" ]

Like this if you want see only collections for non-JS (Shell only), then use the following 

Show collections

Output
Collection1
Collection2

System.Indexes