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]