3. The fixed set of MongoDB learning

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.