MongoDB fixed set
Fixed set
MongoDB fixed set (Capped Collections) is a collection with excellent performance and fixed size. For a fixed size, we can imagine that it is like a circular queue. When the set space is used up, the inserted element will cover the original header element!
Features: you can insert and update, but the update cannot exceed the size of the collection, otherwise the update fails and deletion is not allowed, but you can call drop () to delete all rows in the collection, but you need to explicitly rebuild the collection after drop.
Back to the top.
Example
> db.createCollection (, {capped:, size:, max:: > > db.del_col2.insert ({x:: > db.del_col2.insert ({y:: > db.del_col2.insert ({z:: > db.del_col2.insert ({m:: > db.del_col2. : ObjectId (),:: ObjectId (),: > db.del_col2.insert ({n:: > db.del_col2. ObjectId (),:: ObjectId (),: >: >
Convert to a fixed set
> db.col2.find () {"_ id": ObjectId ("56c6cfd164799370c0ef35a2"), "x": 1} {"_ id": ObjectId ("56c6cfd664799370c0ef35a3"), "y": 2} {"_ id": ObjectId ("56c6cfdf64799370c0ef35a4"), "z": 3} > db.col2.isCapped () false > db.runCommand ({"convertToCapped": "col2", size:1000}) {"ok": 1} > db.col2.isCapped () true