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.

NUnit : Introduction

There are several unit test tools in the market, but one of them is NUnit, the most popular tool for doing unit testing. So in this tutorial...