Difference between revisions of "MongoDB CreateCollection"

From mi-linux
Jump to navigationJump to search
Line 3: Line 3:
  
 
If a collection does not exist, MongoDB will automatically create the collection when you first store data for that 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:
 
You can, however, create one and set some options:
Line 10: Line 15:
 
In this case we are going to limit our collection to hold a maximum of 20 documents.
 
In this case we are going to limit our collection to hold a maximum of 20 documents.
  
 +
To check this has been created:
 +
 +
show collections
  
 
== Next Step ==
 
== Next Step ==
  
 
[[MongoDB_InsertData|Inserting]] data into the collection
 
[[MongoDB_InsertData|Inserting]] data into the collection

Revision as of 15:27, 20 October 2016

Main Page >> MongoDB >>MongoDB Workbook >> Create 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.

To check this has been created:

show collections

Next Step

Inserting data into the collection