MongoDB Create Collection

In MongoDB, db.createCollection(name, alternatives) is utilized to make gathering. In any case, for the most part you don?t need to make accumulation. MongoDB makes accumulation naturally when you embed a few reports. It will be clarified later. To begin with perceive how to make gathering:

							
db.createCollection(name, options);

Name: is a string sort, determines the name of the gathering to be made.

options: is a record sort, determines the memory size and indexing of the accumulation. It is a optional parameter.

The db.createCollection() method has the following prototype form:

db.createCollection(, { capped: ,
                              autoIndexId: ,
                              size: ,
                              max: ,
                              storageEngine:  } )
                              
						
						
						

Following is the list of options that can be used.

Field Type Description
Capped Boolean (Optional) If it is set to genuine, empowers a topped accumulation. Topped accumulation is an altered size collecction that naturally overwrites its most established sections when it achieves its greatest size. On the off chance that you determine genuine, you have to indicate size parameter too.
AutoIndexID Boolean (Optional) If it is set to genuine, naturally make file on ID field. Its default worth is false.
Size Number (Optional) It determines a most extreme size in bytes for a topped gathering. Ifcapped is genuine, then you have to determine this field too.
Max Number (Optional) It specifies the maximum number of documents permitted in the capped collection.

Examples:

Basic syntax of createCollection() method without options is as follows

							
>use test
switched to db test
>db.createCollection("mycollection")
{ "ok" : 1 }
>

Specify Storage Engine Options

You can determine collection-specific storage engine configuration options when you create a collection with db.createCollection(). Consider the accompanying operation:

db.createCollection(
   "users",
   { storageEngine: { wiredTiger: { configString: "

This operation creates a new collection named users with a specific configuration string that MongoDB will pass to the wiredTiger storage engine