mongodb3.6 Series Tutorials 3--Collection Operations _mongodb

Source: Internet
Author: User
1 View All Collections
Show collections
2 Creating a Collection 2.1 syntax
Db.createcollection (name, options)
Parameter description: Name: The names of the collections to be created, required options: The configuration document for the collection, optional

Options parameter Description: Field type description capped Boolean (optional) If true, the Closed collection is enabled. The upper-bound set is a fixed size collection that automatically overwrites its oldest entries when it reaches its maximum large hour. If you specify true, you also need to specify the size parameter. Autoindexid Boolean (optional) If true, the index is automatically created on the _id field. The default value is False. The size number (optional) specifies the maximum size, in bytes, of the upper-bound collection. If capped is true, you also need to specify the value of this field. Max Number (optional) specifies the maximum number of documents allowed in the upper bound collection.

Note: When you insert a document, MongoDB first check the size of the upper-bound collection capped field, and then check the Max field. 2.2 Example

To create a collection using the default configuration:

Db.createcollection ("mycollection")

To create a collection using a custom configuration:

Db.createcollection ("MyCol", {capped:true, autoindexid:true, size:6142800, max:10000})

Note: In MongoDB, if you do not create a collection when you insert some documents, MongoDB automatically creates the collection as follows:

Db.newcollection.insert ({"Name": "Mongodbtest"}) show
collections

The results are as follows:

Mongotest
newcollection
3 Delete Set 3.1 syntax
Db. Collection_name.drop ()

If the selected collection is successfully deleted, the drop () method returns True, or false. 3.2 Example

Delete Name is a collection of newcollection

Db.newcollection.drop ()

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.