Create a collection command for MongoDB db. createCollection

Source: Internet
Author: User
Tags install mongodb
Create a collection command for MongoDB db. createCollection

Create a collection command for MongoDB db. createCollection

The complete command is as follows:
Db. createCollection (name, {capped: , AutoIndexId: , Size: , Max })


Name: Set name
Capped: whether to enable the set restriction. If set restriction is enabled, a restriction condition is disabled by default. This parameter has no practical significance.
Size: limit the size of the space used by the set. The default value is no.
Max: Maximum number of entries in a set. No limit is set by default.
AutoIndexId: whether to use _ id as the index. The default value is true or false)
The priority of size is higher than that of max.


Common Methods:
1. In general, we create a set using db. createCollection (name), such as db. createCollection ("log"): Creates a set named log with no size or quantity restrictions. Use _ id as the default index;

2. restrict the size of the set space: db. createCollection ("log", {size: 1024}) or db. createCollection ("log", {capped: true, size: 1024}), create a set named log, and limit its space to 1 MB. If the size exceeds 1 MB, the oldest record is deleted;
3. Limit the maximum number of sets: db. createCollection ("log", {max: 1024}). Create a collection named log. The maximum number of entries is 1024. If more than 1024 entries are inserted, the earliest record is deleted. This cannot use capped: true; otherwise, an error is returned;
4. the maximum number of restricted items has a limited space: db. createCollection ("log", {size: 1024, max: 1024}) or db. createCollection ("log", {capped: true, size: 1024, max: 1024}), which limits the maximum space used by the set to 1 MB and the maximum number of entries to 1024

The above is obtained by referring to the official documentation and actual tests. It can also be seen that the capped parameter is of no use and can be used without any need.

MongoDB details: click here
MongoDB: click here

Related reading:

MongoDB backup and recovery

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.