发布于 2015-09-14 15:02:44 | 148 次阅读 | 评论: 0 | 来源: 网络整理

db.createCollection(name[, {capped: <boolean>, size: <value>, max <bytes>}])
参数:
  • name (string) – Specifies the name of a collection to create.
  • capped (boolean) – Optional. If this document is present, this command creates a capped collection. The capped argument is a document that contains the following three fields:
  • capped – Enables a collection cap. False by default. If enabled, you must specify a size parameter.
  • size (bytes) – If capped is true, size specifies a maximum size in bytes for the capped collection. When capped is false, you may use size to preallocate space.
  • max (int) – Optional. Specifies a maximum “cap,” in number of documents for capped collections. You must also specify size when specifying max.
Options:
  • autoIndexId – If capped is true you can specify false to disable the automatic index created on the _id field. Before 2.2, the default value for autoIndexId was false. See _id Fields and Indexes on Capped Collections for more information.

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.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务