what is collection in mongodb


What is collection in mongodb

Collection is similar to table of RDBMS and it is use to hold documents of mongodb.

How to Create Collection

db.createCollection(“Collection_name”)  method is use to create collection in MongoDB.

We do not need to create collection. MongoDB creates collection automatically when you insert some documents.

Connect to DB

>use demo
switched to db demo

Show Collection.

>show collections

Please observe above no any collection is there.

Create Collection in mongodb

>db.createCollection("stud")
{ "ok" : 1 }

Show Collection

>show collections
stud

Automatic Creattion of Collection

MongoDB creates collection automatically when we will insert document.

> db.Emp.insert({"roll" : 101,"name","Vikash"}) 
>show collections
stud
Emp






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229