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

  • 相关阅读:
    【C++注意事项】1 数据类型及类型转换
    【万里征程——Windows App开发】动态磁贴
    背包问题
    Fence Repair
    Saruman's Army
    字典序最小问题——Best Cow Line
    区间调度问题
    硬币问题
    数据库查询优化的一些总结
    关于减少BUG的思考
  • 原文地址:https://www.cnblogs.com/jcuan/p/5775944.html
Copyright © 2011-2022 走看看