EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MongoDB Tutorial Mongodb show collections
Secondary Sidebar
MongoDB Tutorial
  • Advanced
    • MongoDB Array
    • PostgreSQL ARRAY_AGG()
    • Indexes in MongoDB
    • MongoDB create Index
    • MongoDB Collection
    • MongoDB List Collections
    • MongoDB Capped Collections
    • MongoDB Delete Collection
    • Mongodb show collections
    • MongoDB Auto Increment
    • MongoDB Triggers
    • MongoDB Projection
    • Replication in MongoDB
    • MongoDB Database
    • Mongo DB Create Database
    • MongoDB Compass
    • MongoDB Users
    • MongoDB Authentication
    • MongoDB GridFS
    • MongoDB Relationships
    • MongoDB MapReduce
    • MongoDB Geospatial
    • MongoDB Monitoring
    • Backup in MongoDB
    • MongoDB Sharding
    • MongoDB Java Drivers
    • MongoDB Import
    • Mongo Database Interview Questions
    • MongoDB Join Two Collections
    • MongoDB Group by Multiple Fields
    • MongoDB Pagination
    • MongoDB Replica Set
    • MongoDB Bulk Update
    • MongoDB greater than
    • MongoDB Encryption
    • MongoDB find in array
    • MongoDB like query
    • Mongodb shell
    • MongoDB port
    • MongoDB Query Operators
    • MongoDB Web Interface
    • MongoDB Query Array
    • MongoDB Transactions
    • MongoDB Not In
    • MongoDB not null
    • MongoDB npm
    • MongoDB Remove
  • Basics
    • What is MongoDB
    • How To Install MongoDB
    • MongoDB Tools
    • MongoDB GUI Tools
    • MongoDB Versions
    • MongoDB Commands
    • Advantages of MongoDB
    • MongoDB Features
    • Is MongoDB NoSQL
    • Is MongoDB Open Source
    • Build Web Applications using MongoDB
    • MongoDB Data Types
    • MongoDB Administration
    • Data Modeling in MongoDB
    • MongoDB vs Elasticsearch
    • MariaDB vs MongoDB
    • Firebase vs MongoDB
  • Commands
    • Mongodb updateMany
    • MongoDB Aggregation
    • Mongodb unwind
    • Mongodb where
    • MongoDB BSON
    • MongoDB Filter
    • Mongodb Match
    • MongoDB sort by date
    • MongoDB Limit()
    • MongoDB Atlas Login
    • MongoDB Relational Database
    • MongoDB count
    • MongoDB Aggregate
    • MongoDB Distinct
    • MongoDB Unique
    • MongoDB find
    • MongoDB findOne()
    • MongoDB insert
    • MongoDB Delete
    • MongoDB Update
    • Lookup in MongoDB
    • order by in MongoDB
    • MongoDB $regex
    • MongoDB $elemMatch
    • MongoDB ObjectId()
    • MongoDB Skip()
    • MongoDB findAndModify
    • Mongodb findOneAndUpdate
    • MongoDB Date Query
    • MongoDB Timestamp
    • MongoDB sort()
    • MongoDB group by
    • MongoDB Join

Related Courses

MongoDB Certification Course

Oracle Certification Course

All in One Data Science Course

SQL Training Course

Oracle DBA Course

MS SQL Certification Course

Mongodb show collections

Mongodb show collections

Introduction to Mongodb show collections

MongoDB show collections are defined as display all collections and views from the connected database; in MongoDB, we can list all collections using the show collections command. There are various methods available to show collections in MongoDB, we can list collections by using show collections, list collections, db.getCollectionNames () and db.getCollectionInfos () methods. Using the show collections command, we can list all collections from the connected database. While working with multiple collections, we need a list of all collections same time; we can use the show collections command in MongoDB.

Syntax 

Below is the syntax of MongoDB show collections are as follows. We can show collections by using the following method.

  • Using show collections command.

show collections

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,650 ratings)
  • Using list collections command.

db.runCommand ({listCollections: <value>, nameOnly: <value>, authorizedCollections: <value>})

  • Using getCollectionNames method.

db.getCollectionNames ()

  • Using getCollectionInfos method.

db.getCollectionInfos (filter (filter collection), nameOnly (Method only return name of collection.), authorized collections (valid value is true or false))

Parameter description of show collections command –

  • Show collections – This method is used in MongoDB to list all the collections and view names from the connected database.
  • List collections – This method is used to list the collection names and all the details in MongoDB. Using this method, we can use multiple parameters to display the details of collections.
  • Name only – This parameter is used in list collections and the getCollectionInfos method. This parameter is used to display the name of the specified collection.
  • Authorized collections – This parameter is used in list collections and the getCollectionInfos method. The valid value of this parameter is true or false; if this value is set as true, then it allowing the user without any required privileges.
  • GetCollectionNames – This method is used in MongoDB to get all the collection names from the specified database in MongoDB.
  • GetCollectionInfos – This method is used to retrieve all the collection names with details from the connected database.

How to show collections in Mongodb?

  • In MongoDB, we can show collections and views using a different method. Below is the method which was used to show collections.
  1. Show collections
  2. List collections
  3. getCollectionNames ()
  4. getCollectionInfos ()
  • To get only the name of the collection and views show collections is the best command to show all collections from the database.
  • To list all the collections and views with details, then we can use the list collections command in MongoDB.
  • Using the getCollectionNames command, we can only list all the collection names in format.
  • If we have to find all the collection names with details and specified collection names with details, then we can use the getCollectionInfos method in MongoDB.
  • To list the collection of specified databases, we need to first connect to that database; after connecting to the database, we can list all the collections and views. Without connecting to the specified database, it’s not possible to show the collections.
  • The below example shows that we need to connect the specified database to show the collection.

use test
show collections

Mongodb show collections output 1

Figure – we need to connect the specified database to show the collection.

  • In the above example, we have first connected to the test database and then used the show collections command to list the collections from the test database.
  • We can list only those collections on which we have access; without access, we can’t list the collection from the database.

Example

Here are the following examples mentioned below

1 Show collection using show collections command

  • The below example shows show all the collections using the show collections command.
  • We have listed all the collections from the test database. Before using this command, we have connected to the test database. The test database contains the 5 collections in it.

Code:

use test
show collections

Mongodb show collections output 2

Figure – Show collection using show collections command.

2. Show collection using list collections command

  • The below example shows show collection by using the list collection command. We have used authorized collection and name the only parameter with the list collection command.
  • In the below example, we list the collection from the coll_test database. Coll_test database contains only one collection, so it will show detailed info of collection_test collection.
  • In the below image, we can see it will show all details info like name of the collection, type, etc.

Code:

use coll_test
db.runCommand ({listCollections: 1.0, authorizedCollections: true, nameOnly: true })

Mongodb show collections output 3

Figure – Show collection using the list collections command in MongoDB.

3. Show collection using getCollectionNames method

  • The below example shows a list of the collection by using the getCollectionNames method.
  • In the below example, we have list the collection from the test database. The test database contains five collections, so it will show all five collection names in format.
  • In the below image, we can see that the output only shows the name of the collection which is present in the test collection.

Code:

use test
db.getCollectionNames ()

output 4

Figure – Show collection using getCollectionNames method in MongoDB.

4. Show collection using getCollectionInfos method

  • The below example shows show collection by using the getCollectionInfos method. In the first example, we have used authorized collection, filter, and name, the only parameter with the getCollectionInfos method.
  • In the below example, we list the collection from the coll_test database. Coll_test database contains only one collection, so it will show detailed info of collection_test collection.

Code:

use coll_test
db.getCollectionInfos ({}, true, true)

output 5

Figure – Show collection using the getCollectionInfos method using a parameter.

  • In the below example, we have not used any parameter with the getCollectionInfos method.

Code:

use coll_test
db.getCollectionInfos ({}, true, true)

output 6

Figure – Show collection using the getCollectionInfos method, excluding the parameter.

5. Show single collection details using the getCollectionInfos method

  • In the below example, we have used the collection name using the getCollectionInfos method.
  • We have used collection_test collection to display single collection details. With the getCollectionInfos method, we have used all the parameters.

Code:

use coll_test
db.getCollectionInfos ({name: "collection_test"}, true, true)

output 7

Figure – Show single collection details using getCollectionInfos method in MongoDB.

Conclusion

Show collection command is used to list all the collections and views from connected databases. We can use show collections, list collections getCollectionInfos, and getCollectionNames method to show all the collections from the connected database. To list the view and collection, first, we need to connect the specified database.

Recommended Articles

This is a guide to Mongodb show collections. Here we discuss How to show collections in Mongodb along with the Parameter description of the show collections command. You may also have a look at the following articles to learn more –

  1. MongoDB findOne()
  2. MongoDB Skip()
  3. SQL GROUP BY Month
  4. MongoDB Users
Popular Course in this category
MongoDB Training Program (4 Courses, 2 Projects)
  4 Online Courses |  2 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle Training (14 Courses, 8+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
SQL Training Program (7 Courses, 8+ Projects)4.7
Oracle DBA Database Management System Training (2 Courses)4.7
MS SQL Training (16 Courses, 11+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more