MongoDB CreateComplexCollection

From mi-linux
Revision as of 12:23, 10 November 2017 by Cm1958 (talk | contribs) (Created page with "Main Page >> MongoDB >>MongoDB Workbook >> Create Complex Collections == Create a Collection == If a collection does not exist, MongoDB w...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Main Page >> MongoDB >>MongoDB Workbook >> Create Complex Collections

Create a Collection

If a collection does not exist, MongoDB will automatically create the collection when you first store data for that collection.

When you first use MongoDB you will find you have no collections:

show collections

You can, however, create one and set some options:

db.createCollection('deptCollection', {max: 20})

In this case we are going to limit our collection to hold a maximum of 20 documents.


This command should return:

 db.createCollection('deptCollection', {max: 20})
 { "ok" : 1 }


To check this has been created:

show collections

Next Step

Inserting data into the collection