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

转载于:https://www.cnblogs.com/jcuan/p/5775944.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值