How to list all collections from a particular MongoDB database?

MongoDBDatabaseBig Data Analytics

If you want to list all collections from a particular database then you need to switch the database first. The query is as follows −

> use sample;
switched to db sample
> db.getCollectionNames();

The following is the output −

[
   "copyThisCollectionToSampleDatabaseDemo",
   "deleteDocuments",
   "deleteDocumentsDemo",
   "deleteInformation",
   "employee",
   "internalArraySizeDemo",
   "sourceCollection",
   "updateInformation",
   "userInformation"
]

An alternate query can be the following −

> show collections;

The following is the output −

copyThisCollectionToSampleDatabaseDemo
deleteDocuments
deleteDocumentsDemo
deleteInformation
employee
internalArraySizeDemo
sourceCollection
updateInformation
userInformation
raja
Published on 28-Mar-2019 11:33:11
Advertisements