How to list all collections in the MongoDB


MongoDB is my favorite database here everything goes 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 to see only collections for non-JS (Shell only), then use the following 

Show collections

Output
Collection1
Collection2

System.Indexes

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...