Create new collection(table) in mongoDB

You are here : Home / MongoDB Tutorial



Contents of page >
  • 1) Create new collection(table) in mongoDB>
  • 2) See list of all tables (collections) in database in MongoDb >


1) Create new collection(table) in mongoDB>

Use createCollection() method to create collection in mongoDB>
> db.createCollection("employeeTable ")
{ "ok" : 1 }
>


Create new collection in different database in mongoDB>
> use testdb;
switched to db testdb
> db.createCollection("employeeTable ")
{ "ok" : 1 }
>
First we switched to testdb, and then created collection in it.




2) See list of all tables (collections) in database in MongoDb >
We can use following ways to see list of all collections in database in MongoDb >

> show collections

OR

> show tables

OR

> db.getCollectionNames()


You can see two tables>
employeeTable (Table which we just created above)
System.indexes  (It is default table)



Note : (Table and collection are same thing in mongoDB),
(Record/Row and document are same thing in mongoDB)


SUMMARY>
So in this mongoDB tutorial we learned how to Create new collection(table) in mongoDB using  createCollection() method.


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>

Difference in MongoDB and RDBMS - What are Database, collection, document and field in MongoDB


See list of all databases in MongoDb, switch database


Drop database in mongoDB

Labels: MongoDB
eEdit
Must read for you :