Check if a Collection is Capped
On this page
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of MongoDB server.
To check if a collection is capped, use the
isCapped()
method.
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.
Capped collections serialize inserts and therefore have worse concurrent insert performance than non-capped collections. Before you create a capped collection, consider if you can use a TTL index instead.
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:
db.nonCappedCollection1.isCapped() db.cappedCollection1.isCapped()
false true