...

Database Managment - Mongo DB

Back to Course

Lesson Description


Lession - #1404 MongoDB Create Collection


MongoDB - Create Collection

The createCollection(>
Method
MongoDB db.createCollection(name, choices>
is utilized to make assortment. Linguistic structure Essential sentence structure of createCollection(>
order is as per the following −

db.createCollection(name, options>

In the order, name will be name of assortment to be made. Choices is a report and is utilized to indicate setup of assortment.
Parameter Type Description
Name String Name of the collection to be created
Options Document (Optional>
Specify options about memory size and indexing

Choices boundary is discretionary, so you really want to indicate just the name of the assortment. Following is the rundown of choices you can utilize −
Field Type Description
capped Boolean (Discretionary>
If valid, empowers a covered assortment. Covered assortment is a decent size assortment that naturally overwrites its most seasoned sections when it arrives at its greatest size. On the off chance that you indicate valid, you want to determine size boundary moreover.
autoIndexId Boolean (Discretionary>
If valid, consequently make file on _id field.s Default esteem is misleading
size number (Discretionary>
Specifies a most extreme size in bytes for a covered assortment. In the event that covered is valid, you really want to determine this field too.
max number (Discretionary>
Specifies the most extreme number of records permitted in the covered assortment.
While embedding the record, MongoDB first checks size field of covered assortment, then it checks max field. Examples: Essential grammar of createCollection(>
technique without choices is as per the following −

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

You can check the created collection by using the command show collections.

>show collections
mycollection
system.indexes

The following example shows the syntax of createCollection(>
method with few important options −

> db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } >
{ "ok" : 0, "errmsg" : "BSON field 'create.autoIndexID' is an unknown field.", "code" : 40415, "codeName" : "Location40415" } >

In MongoDB, you don't need to create collection. MongoDB creates collection automatically, when you insert some document.

>db.tutorialspoint.insert({"name" : "tutorialspoint"}>
, WriteResult({ "nInserted" : 1 }>
>show collections mycol mycollection system.indexes tutorialspoint >


install mongodb centos 7

install mongodb centos 7

mongodb tutorial for beginner

mongodb tutorial for beginner

mongodb macos

mongodb macos

mango database

mango database

mongodb debain

mongodb debain

mongodb raspberry pi

mongodb raspberry pi

homebrew mongodb

homebrew mongodb