MONGODB CREATE DATABASE and collection commands db.createcollection detailed

Source: Internet
Author: User
Tags install mongodb mongodb create database

Switch/CREATE Database

Use Yourdb; The current database is created automatically when a collection (table) is created

The complete command is as follows:
Db.createcollection (name, {capped: <boolean>, Autoindexid: <boolean>, size: <number>, Max <number })


Name: Collection of names
Capped: Whether to enable the collection limit, if you need to set a constraint, default is not enabled, this parameter does not make sense
Size: Limits the amount of space used by the collection, which is not limited by default
Max: Limit of maximum number of bars in the collection, defaults to No limit
AUTOINDEXID: Whether to use _id as the index, by default (TRUE or FALSE)
Size has a higher priority than max


Common methods introduced:
1, in general, we create a collection with Db.createcollection (name), such as: Db.createcollection ("Log"), create a collection named log, without any size, quantity limit, using _id as the default index;

2. Limit the size of the collection space: Db.createcollection ("Log", {size:1024}) or db.createcollection ("log", {capped:true,size:1024}), Create a name for the log collection, limit its space size is 1M, if it exceeds the size of 1M, it will delete the oldest record;
3, limit the maximum number of sets: Db.createcollection ("Log", {max:1024}), create a name for the log collection, the maximum number of bars is 1024, more than 1024 and then insert the data will delete the oldest record. This can not use Capped:true, or will error;
4, that is, limit the maximum number of bars to use space size: db.createcollection ("Log", {size:1024,max:1024}) or db.createcollection ("log", {capped:true,size : 1024,max:1024}), limit collection maximum usage space is 1M, maximum number of bars is 1024

The above is a reference to the official documents and the actual test results, you can also see that the capped parameter is not useful, use not all can.

a detailed description of MongoDB : please click here
MongoDB : please click here.

Related reading :

MongoDB Backup and Recovery http://www.linuxidc.com/Linux/2012-07/64113.htm

CentOS Compile Install MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htm

CentOS compilation installs MongoDB with MongoDB PHP extension http://www.linuxidc.com/Linux/2012-02/53833.htm

CentOS 6 uses Yum to install MongoDB and server-side configuration http://www.linuxidc.com/Linux/2012-08/68196.htm

Ubuntu 13.04 under Install MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htm

How to create a new database and collection in MongoDB http://www.linuxidc.com/Linux/2013-06/85749.htm

MongoDB entry must read (both concept and actual combat) http://www.linuxidc.com/Linux/2013-07/87105.htm

The MongoDB authoritative guide (mongodb:the definitive) English language version [PDF] Http://www.linuxidc.com/Linux/2012-07/66735.htm

MONGODB CREATE DATABASE and collection commands db.createcollection detailed (GO)

Related Article

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.