Nowadays, organizations across the world have started adopting the NoSQL database to provide solutions to various business problems. NoSQL databases have gained popularity due to the features that they contain. There are multiple open-source NoSQL databases that are available in the market and MongoDB is one among them.
MongoDB is defined as a NoSQL Open Source database that supports different forms of data. It is designed in a manner to support the large volume storage requirements of various organizations. It is a distributed database at its core and has inbuilt features such as high availability, geographic distribution, and horizontal scaling that make it simple to use.
If you want to enrich your career and become a professional in MongoDB, then visit Mindmajix - a global online training platform: "MongoDB Training" This course will help you to achieve excellence in this domain.
MongoDB show collection is a command from the MongoDB shell that helps in listing the collections created in the current database. To view the collection, you need to select the one that you want to view.
If you want to list the available collections in the MongoDB database, all you need to do is select the mydb, then run the show collection command
Related blog: Checkout MongoDB Tutorial
> use mydb
> show collections
Output
Mindmajix
Students
Leads
Servies
Employees
Frequently Asked MongoDB Interview Questions
We use the below-mentioned command to create a collection in the database:
db.createcollection( name, options )
A collection is a group of MongoDB documents that exists within a table.
Below mentioned are the steps to be followed to create a collection:
Here in MongoDB, you need to insert a document before you are going to create a collection. Using a simple command, you can insert a document in the command collection, and then the MongoDB create collection instantaneously. The syntax we use to insert a document is shown below.
Related blog: Create MongoDB Collection
Syntax:
db.collection_name.insert({key:value, key:value…})
Let's consider an example here:
We are not having a collection of student's profiles in the studentprofileDB. We can easily create a collection named “studentsprofile” very quickly and we can insert a document by allocating keys and value pairs.
> use studentsprofile
Switched to db studentsprofile
db.studentsprofile .insert({
name: "Naveen",
age: 21,
website: "studentsprofile.com"
})
Now, you can see the command prompt as shown below.
writeResult({"nInserted" : 1 })
Administrator: Command Prompt - mongo -
> db.beginnersbook.insert({
. . . name: "Naveen",
. . . age: 30,
. . .website: "studentsprofile.com"
. . . })
WritenResult ({ "nInserted" : 1 })
>
If you want to have a check over whether the document is successfully implemented or not, just type the following command. It will display you the documents in the list of collections.
Syntax:
db.collection_name.find()
> db.studentsprofile.find()
{ "_id" : objectId("48bc9d3524235cdb68ba77"), "name" : "Naveen",
"age" : 30, "website" : "studentsprofile.com" }
Use the below command to check whether the collection is created successfully or not.
Show collection
The below-mentioned command shows the list of all the collections in the currently selected database.
> show collections
studentsprofile
You might have got a clear idea about what is MongoDB and how to create a collection in MongoDB. Hope this blog helped you in gaining some knowledge on show collection and command lines.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
MongoDB Training | Nov 19 to Dec 04 | View Details |
MongoDB Training | Nov 23 to Dec 08 | View Details |
MongoDB Training | Nov 26 to Dec 11 | View Details |
MongoDB Training | Nov 30 to Dec 15 | View Details |
Vinod M is a Big data expert writer at Mindmajix and contributes in-depth articles on various Big Data Technologies. He also has experience in writing for Docker, Hadoop, Microservices, Commvault, and few BI tools. You can be in touch with him via LinkedIn and Twitter.