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 Answers
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:
queue will not remove records when full (it could throw an exception like out of memory)
queue can remove record when dequeued - in capped collection you need to delete it on your own
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!

- 9,213
- 3
- 31
- 52
-
Thanks, okay to recap :) - Queues can remove old elements (FILO) automatically. - In capped collections cleanup happens explicitly (?) – dmi3y Apr 28 '16 at 17:25
-
1@dmi3y in capped collection there is no cleanup. The older documents are just removed from it. So if capped collection size is 40 documents - then when 41 is added -> 1 is removed – profesor79 Apr 28 '16 at 21:16
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.

- 1,212
- 2
- 16
- 29
-
Thanks for the info, though can you elaborate more, this does not really make things clear for me. – dmi3y Apr 28 '16 at 17:17