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 }
Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close