发布于 2015-09-14 15:02:44 | 148 次阅读 | 评论: 0 | 来源: 网络整理
参数: |
|
---|---|
Options: |
|
Explicitly creates a new collection. Because MongoDB creates collections implicitly when referenced, this command is primarily used for creating new capped collections. In some circumstances, you may use this command to pre-allocate space for an ordinary collection.
Capped collections have maximum size or document counts that prevent them from growing beyond maximum thresholds. All capped collections must specify a maximum size, but may also specify a maximum document count. MongoDB will remove older documents if a collection reaches the maximum size limit before it reaches the maximum document count. Consider the following example:
db.createCollection("log", { capped : true, size : 5242880, max : 5000 } )
This command creates a collection named log with a maximum size of 5 megabytes and a maximum of 5000 documents.
The following command simply pre-allocates a 2 gigabyte, uncapped collection named people:
db.createCollection("people", { size: 2147483648 })
This command provides a wrapper around the database command create. See 封顶集合 for more information about capped collections.