I'am trying to figure out a way to use Mongo as a circular buffer. Currently using SQL Lite but performance wise does not fit our case. The specifications need to be met are: The collection must empty itself every x seconds. The collection must empty itself when a limit of y documents is met.
Going through Mongo documentation, capped collections along with change events seem a way to go.
https://docs.mongodb.com/manual/core/capped-collections/
https://docs.mongodb.com/manual/reference/change-events/
In the documentation states: "Capped collections work in a way similar to circular buffers"
However I am not sure how to:
- Empty the collection every x seconds. Mongo TTL feature is not feasible since TTL isn't supported on capped collections.Other alternatives?
- Retrieve any "removed documents". Replace operation type of Change Events seems an aproach.Other alternatives?
Has anyone tried using Mongo as circular buffer? Is the above -Capped Collections/Change Events- the way to achive it?
Thanks for any response.