Skip to content

Instantly share code, notes, and snippets.

@adrianolsk
Created December 4, 2017 13:59
Show Gist options
  • Save adrianolsk/812ec57d44dd48d608c9a2822ba80f0f to your computer and use it in GitHub Desktop.
Save adrianolsk/812ec57d44dd48d608c9a2822ba80f0f to your computer and use it in GitHub Desktop.
Today I learned

#Capped Collections

Overview

Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.

#Restrictions and Recommendations

Updates

If you plan to update documents in a capped collection, create an index so that these update operations do not require a collection scan.

Document Size

Changed in version 3.2.

If an update or a replacement operation changes the document size, the operation will fail.

Document Deletion

You cannot delete documents from a capped collection. To remove all documents from a collection, use the drop() method to drop the collection and recreate the capped collection.

Sharding

You cannot shard a capped collection.

Query Efficiency

Use natural ordering to retrieve the most recently inserted elements from the collection efficiently. This is (somewhat) analogous to tail on a log file.

Aggregation $out

The aggregation pipeline operator $out cannot write results to a capped collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment