版权声明:本文为博主原创文章,未经博主允许欢迎转载,请注明原文链接。一起交流,共同进步。 https://blog.csdn.net/newbie_907486852/article/details/82355447
Capped Collections介绍及生产环境之疲劳度过滤、日志应用
1、capped collection(上限集合)
一个集合,它可以做到size的上限 和 document个数的上限。
bytes maxinum 指定collection的大小。
document maxinum 指定collection中的document的个数(当document个数超过指定个数,只保留最新的。)。
2、代码去创建 capped collection
db.createCollection(<name>, { capped: <boolean>,
autoIndexId: <boolean>,
size: <number>,
max: <number>,
storageEngine: <document>,
validator: <document>,
validationLevel: <string>,
validationAction: <string>,
indexOptionDefaults: <document> } )
3、倒序查询capped collection
var list=db.logs.find().sort( { $natural: -1 } ).toArray();
4、普通集合 转换为 上限集合
db.runCommand({"convertToCapped": "collectionName", size: 100000});