发布于 2015-09-14 14:56:51 | 123 次阅读 | 评论: 0 | 来源: 网络整理

create

The create command explicitly creates a collection. The command uses the following syntax:

{ create: <collection_name> }

To create a capped collection limited to 40 KB, issue command in the following form:

{ create: "collection", capped: true, size: 40 * 1024 }

The options for creating capped collections are:

Options:
  • capped – Specify true to create a capped collection.
  • autoIndexId – 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.
  • size – The maximum size for the capped collection. Once a capped collection reaches its max size, MongoDB will drop old documents from the database to make way for the new documents. You must specify a size argument for all capped collections.
  • max – The maximum number of documents to preserve in the capped collection. This limit is subject to the overall size of the capped collection. If a capped collection reaches its maximum size before it contains the maximum number of documents, the database will remove old documents. Thus, if you use this option, ensure that the total size for the capped collection is sufficient to contain the max.

The db.createCollection() provides a wrapper function that provides access to this functionality.

注解

This command obtains a write lock on the affected database and will block other operations until it has completed. The write lock for this operation is typically short lived; however, allocations for large capped collections may take longer.

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

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