Difference between revisions of "MongoDB CreateComplexCollection"

From mi-linux
Jump to navigationJump to search
(Created page with "Main Page >> MongoDB >>MongoDB Workbook >> Create Complex Collections == Create a Collection == If a collection does not exist, MongoDB w...")
 
Line 1: Line 1:
[[Main Page]] >> [[MongoDB|MongoDB]] >>[[MongoDB_Workbook|MongoDB Workbook]] >> Create Complex Collections
+
[[Main Page]] >> [[MongoDB|MongoDB]] >>[[MongoDB_Workbook|MongoDB Workbook]] >> Create Complex Collection
 
== Create a Collection ==
 
== Create a Collection ==
  
If a collection does not exist, MongoDB will automatically create the collection when you first store data for that collection.
+
This time we will create a collection in advance and add some nested documents to it.
  
When you first use MongoDB you will find you have no collections:
+
Check what collections you have already:
  
  show collections
+
  show collection
  
You can, however, create one and set some options:
+
Now create a new one called ''deptCollection'' and set some options:
  
 
  db.createCollection('deptCollection', {max: 20})
 
  db.createCollection('deptCollection', {max: 20})

Revision as of 12:25, 10 November 2017

Main Page >> MongoDB >>MongoDB Workbook >> Create Complex Collection

Create a Collection

This time we will create a collection in advance and add some nested documents to it.

Check what collections you have already:

show collection

Now create a new one called deptCollection 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