Fixed Collection
The MongoDB fixed set (Capped collections) is a well-performing and fixed-size set, and for a fixed size we can imagine it to be like a ring queue , and when the set space is exhausted, the inserted element will overwrite The most initial element of the head!
Features: can be inserted and updated, but the update cannot exceed the size of the collection, otherwise the update fails, the deletion is not allowed, but you can call drop () to delete all the rows in the collection, but you need to explicitly rebuild the collection after the drop.
Back to Top
Example
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>
> 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 (),: >::: >
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>
Convert to Fixed set
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin:0px;padding:0px;border:none; "/>
> Db.col2.find () {"_id": ObjectId ("56C6CFD164799370C0EF35A2"), "X": 1} {"_id": ObjectId ("56C6CFD664799370C0EF35A3" ), "Y": 2} {"_id": ObjectId ("56c6cfdf64799370c0ef35a4"), "Z": 3}> db.col2.isCapped () false> Db.runcommand ({"Conv Erttocapped ":" Col2 ", size:1000}) {" OK ": 1}> db.col2.isCapped () True
MongoDB Fixed Collection