I have a collection that use as a cache. How can I limit the documents number to 5M inside this collection.
Note: that the cache item can be updated will existing in the cache.
I use tried to use capped, but the item saves in a capped collection cannot be modified.
Is there a way to do that?
(i would like to avoid delete the item and then insert the update one)
Unfortunately, there’s not much you can do here. As you noted, documents in capped collections can’t be modified. And also, you can’t specify a limit in documents, it’s in megabytes, IIRC.
So, your best bet is to use normal collection and have a periodic job that’ll check the collection for overflows and will clean up old documents.