zoukankan      html  css  js  c++  java
  • mongodb Capped Collections 固定集合

    特点

    • 像队列,插入的效率很高,size大小固定(还可以指定max限制文档个数),自动按照插入的顺序返回文档
    • 不能从capped集合中删除文档,只能整个集合一块删除
    • 不能sharding

    使用

    When creating a capped collection you must specify the maximum size of the collection in bytes, which MongoDB will pre-allocate for the collection. The size of the capped collection includes a small amount of space for internal overhead.

    db.createCollection( "log", { capped: true, size: 100000 } )
    

    注意:

    If the size field is less than or equal to 4096, then the collection will have a cap of 4096 bytes. Otherwise, MongoDB will raise the provided size to make it an integer multiple of 256.

    指定文档个数

    db.createCollection("log", { capped : true, size : 5242880, max : 5000 } )
    

    使用natural操作符

    可以让返回顺序变为插入的逆序

    db.cappedCollection.find().sort( { $natural: -1 } )
    

    Check if a Collection is Capped

    db.collection.isCapped()
    

    Convert a Collection to Capped

    db.runCommand({"convertToCapped": "mycoll", size: 100000});
    

    Automatically Remove Data After a Specified Period of Time

    consider MongoDB’s TTL indexes,
    see mongodb manual

  • 相关阅读:
    Android之Activity启动过程
    Android之Application进阶
    Android之Context进阶
    Thread之ThreadLocal
    Android 系统服务与Binder应用服务
    Android Binder
    Android SystemServer
    Android系统服务与服务注册
    Android Binder进阶扁一
    小米商城-题头3
  • 原文地址:https://www.cnblogs.com/jcuan/p/5775944.html
Copyright © 2011-2022 走看看