笔记-capped collection

笔记-capped collection 

1.      collection

1.1.    简介

集合分为固定与非固定collection,capped collection

 

1.1.1.   capped collections

Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.

Capped collections 是固定大小的collection。它支持高速吞吐,这是基于插入顺序实现的。它的工作原理类似于循环缓冲区,一旦接近预定的存储空间限制,它会覆盖集合中最老的文档。

 

 

1.2.    CURD

1.2.1.   create

capped colletions 需要显示创建;使用createcollection方法

db.createCollection(<name>, { capped: <boolean>,

                              autoIndexId: <boolean>,

                              size: <number>,

                              max: <number>,

                              storageEngine: <document>,

                              validator: <document>,

                              validationLevel: <string>,

                              validationAction: <string>,

                              indexOptionDefaults: <document>,

                              viewOn: <string>,

                              pipeline: <pipeline>,

                              collation: <document>,

                              writeConcern: <document>} )

 

参数释义:

capped:

size:文档空间限制,单位是bytes;只对capped collection生效

max:用于限制文档数,使用时需注意与size的配合。

下面是一些案例:

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

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

 

1.2.2.   Updates

If you plan to update documents in a capped collection, create an index so that these update operations do not require a collection scan.

 

1.2.3.   delete

You cannot delete documents from a capped collection. To remove all documents from a collection, use the drop() method to drop the collection and recreate the capped collection.

capped collection不支持删除文档操作,清除所有文档的方法是drop()集合然后重新创建。

1.2.4.   document size

如果更新或替换操作会导致文档大小改变,操作会失败。

If an update or a replacement operation changes the document size, the operation will fail.

1.3.    其它操作

检查是否为capped集合

db.collection.isCapped()

 

转换普通集合为限制集合

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

 

转载于:https://www.cnblogs.com/wodeboke-y/p/10835054.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值