To check if a collection is capped, use the 要检查集合是否封顶,请使用isCapped() method.isCapped()方法。
About this Task关于此任务
Generally, TTL (Time To Live) indexes offer better performance and more flexibility than capped collections. TTL indexes expire and remove data from normal collections based on the value of a date-typed field and a TTL value for the index.通常,TTL(生存时间)索引比封顶集合提供更好的性能和更大的灵活性。TTL索引过期,并根据日期类型字段的值和索引的TTL值从正常集合中删除数据。
Capped collections serialize write operations and therefore have worse concurrent insert, update, and delete performance than non-capped collections. Before you create a capped collection, consider if you can use a TTL index instead.封顶的集合序列化写操作,因此与非封顶的集合相比,其并发插入、更新和删除性能较差。在创建封顶集合之前,请考虑是否可以使用TTL索引。
Before you Begin开始之前
Create a non-capped collection and a capped collection:创建非封顶集合和封顶集合:
db.createCollection("nonCappedCollection1")
db.createCollection("cappedCollection1", { capped: true, size: 100000 } )Steps步骤
To check if the collections are capped, use the 要检查集合是否封顶,请使用isCapped() method:isCapped()方法:
db.nonCappedCollection1.isCapped()
db.cappedCollection1.isCapped()
false
true