1

I have an application that allows users to chat with other users,

I only want to store X messages per each conversation, AND each message must be deleted after 1 month since its creation (TTL)

MongoDB support capped collections with TTL?

The documentation says: https://docs.mongodb.org/manual/core/capped-collections/#automatically-remove-data-after-a-specified-period-of-time

For additional flexibility when expiring data, consider MongoDB’s TTL indexes, as described in Expire Data from Collections by Setting TTL. These indexes allow you to expire and remove data from normal collections using a special type, based on the value of a date-typed field and a TTL value for the index.

TTL Collections are not compatible with capped collections.

I think not, so, there is any alternative to accomplish it?

Thanks

fj123x
  • 6,904
  • 12
  • 46
  • 58
  • Why do you use capped collections then? It does not solve any of the disclosed requirements. – Alex Blex Feb 09 '16 at 10:21
  • yes, it allows me to only store X messages, with capped collections if I fix the collection to 100 items (or bytes), if i insert the item 101, the oldest items would be removed – fj123x Feb 09 '16 at 11:02
  • Ah, I see, so you create a collection per-conversation. – Alex Blex Feb 09 '16 at 11:09

0 Answers0