A capped collection is a fixed-size MongoDB collection designed to keep recent documents. It can also have a document-count limit. Like a circular buffer, it makes room at its size limit by replacing the oldest documents with new ones. section 2.6.3
Capped collections preserve insertion order. Documents can be retrieved in that order without an index for it, reducing indexing overhead and supporting high-throughput inserts and retrievals. section 2.6.3
Use one when retaining the newest data matters more than retaining every record:
- High-volume logs: first-in-first-out retention keeps events in sequence while bounding storage; writes without indexes can be nearly as fast as filesystem logging. section 2.6.3
- Small caches: recent entries are often the most useful, though necessary indexes may add some overhead; keeping a read-heavy cache in RAM is preferable where possible. section 2.6.3
Choose a capped collection only if automatic replacement is acceptable: reaching the limit removes older data. If those documents must remain available, that behavior is a poor fit. For automatically expiring data, MongoDB also offers time-to-live indexes; for timestamped metrics or device data, it offers time-series collections. section 2.6.3 section 1.3.1
