A fixed set of MongoDB fixed set refers to the pre-created, and fixed-size set. That is, if a set is fixed to 100, and then a document is added, the first document will be removed, leaving only 100 data. Fixed set properties: Fixed sets are much like ring queues, and if there is not enough space, Zakura documents are deleted, freeing up space for new documents. In general, fixed collections are suitable for any scenario where you want to automatically retire expired attributes. Second, fixed set of application scenarios such as log files, chat records, call information records, etc. need to retain the recent period of time in the application scenario, will apply to the fixed set of MongoDB. When the number of documents is known, the size must be specified at the same time, the elimination mechanism is not satisfied when the capacity will be based on the number of documents to work, if the capacity is full, the elimination mechanism will be eliminated according to the capacity mechanism. How to apply a fixed set create a fixed collection using the command: Db.createcollection (name, {size: ..., capped: ..., max: ...}) Name #表示集合名称capped #为true表示固定集合size #表示集合最大使用的大小, default is Kmax #表示最大的文档数 1, create a fixed collection > db.createcollection ("B3", {CA PPED:TRUE,SIZE:1024,MAX:200}) 2, insert data to Fixed set > for (var i=1;i<199;i++) {... db.b3.insert ({name: ' Test ' +i,age:26}) ... } Writeresult ({"ninserted": 1}) 3, view collection Writeresult ({"ninserted": 1}) > Db.b3.find () #可以看到集合已经size就已经把文档剔除了
3. The fixed set of MongoDB learning