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 ()