MongoDB Collection Management One

Source: Internet
Author: User

A few recent blog is about MongoDB, although the personal feel also not much knowledge point, but unexpectedly have reproduced my blog, regardless of whether I agree or not through my consent, the description should still be valuable, this is one of the driving force of my blog. On a blog to learn the management of the database, today to learn the management of the collection. For these basic are additions and deletions to change the search.

I. Displaying a list of collections in a database

Refer to the list of previously displayed databases can be guessed under may also use show, set words that may be plural form, because the database list is show DBS, set that may be show set S. And then I see that it really is, using show collections.

Second, create the collection

As mentioned in the previous blog creation database, there is no explicit statement to create a database and a database handle is created and a collection is created. However, there is an optional attribute when creating a collection.

Capped: Boolean value, True: Indicates that the collection is a capped collection and does not grow larger than the maximum size specified by the Size property. False by default.

AutoIndex: Boolean, true: Indicates that a _id field is automatically created for each document added to the collection and the index on that field is implemented. This pair cap set should be false. Default true.

Size: in bytes. Used to cap the set. The oldest file is deleted to make room for the new file

Max: The maximum number of documents allowed in the capping collection. The oldest file is deleted to make room for the new file

Third, delete the collection

Deleting a database using drop, deleting the collection is also using drop, basically the same. To delete the database when you want to switch to a specific database, delete the collection when you want to get to the collection object after using drop delete.

Here are the experiments I did.

As you can see in the above, I first list the database, then go to the TestDB database, show that the list of collections under that database has only one person, and then use CreateCollection to create a collection student, at which point the list of collections shows two. Then, get the collection person object coll, use drop to delete a few, at this time the collection list left one.

MongoDB Collection Management One

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.