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