Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Check if a Collection is Capped

On this page

  • About this Task
  • Before you Begin
  • Steps
  • Learn More

To check if a collection is capped, use the isCapped() method.

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 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.

Create a non-capped collection and a capped collection:

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

To check if the collections are capped, use the isCapped() method:

db.nonCappedCollection1.isCapped()
db.cappedCollection1.isCapped()
false
true

Back

Query