Capped collections vs Queues

706 Views Asked by At

I'm trying to understand what is the capped collection is, specifically in context of MongoDB, and what would be the difference in compare with queue?

2

There are 2 best solutions below

2
On BEST ANSWER

Capped collection will remove oldest document when it reaches it limit, so that could be an issue if there is a need to process ALL documents from capped collection.

from mongo: 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.

comparing to queue:

  1. queue will not remove records when full (it could throw an exception like out of memory)

  2. queue can remove record when dequeued - in capped collection you need to delete it on your own

  3. capped collection cleanup: if capped collection size is 40 documents - then when 41st document is added -> the 1st entry is removed

I think this the most important things - any comments welcome!

1
On

CAPPED collection in mongodb is implementation of circular buffer.

From official documentation

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.

enter image description here