Search code examples
mongodbdata-structuresqueuecapped-collections

Capped collections vs Queues


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?


Solution

  • 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!