MongoDB Create Collection

MongoDB Create Collection

 MongoDB Create Collection


MongoDB stores documents in collections. The collections are analogous to tables in relational databases like MySQL. Generally, you don’t need to create a collection, MongoDB does this automatically during the insertion of the first document.

Syntax

Use db.createCollection() command to create collection. You need to specify the name of the collection, Also can provide some optional options like memory size and indexing.

> db.createCollection(name, options)   

MongoDB – Create Collection

Login to Mongo shell and select your database with the following command.

> use mydb

Now create your collection with createCollection() command. The below command will create a collection named mycol in the current database.

> db.createCollection("TECADMIN")  

{ "ok" : 1 }
Reactions

Post a Comment

0 Comments

close