[MongoDB] Capped fixed set
Unlike normal collections, fixed collections must be displayed and created before use, and you can use the create command to create fixed collections. In shell, you can use the db.createCollection function:
/ / create a fixed collection db.createCollection ("capped", {capped:true,size:1024}) with a size of 1024 bytes; / / create a fixed collection db.createCollection ("capped", {capped:true,size:1024,max:100}) with a size of 1024 bytes and the number of documents
It is worth noting that the size parameter is required and the max parameter is optional. No matter which limit is reached first, the new documents inserted later squeeze the old documents out of the collection, the number of documents in the fixed collection cannot exceed the set number of documents, and the size of the fixed collection cannot exceed the set size.
After the fixed collection is created, it cannot be changed. If you need to modify the properties of the fixed collection, you can only delete it and then create it. Therefore, you should think carefully about its size before creating a large fixed collection.
In addition, you can use the convertToCapped command to convert a regular collection to a fixed collection:
Db.runCommand ({convertToCapped: "test", size:1024, max:100})
Note that you cannot convert a fixed collection to a non-fixed collection.