1

我有一个允许用户与其他用户聊天的应用程序,

我只想为每个对话存储 X 条消息,并且每条消息必须在创建后 1 个月后删除(TTL)

MongoDB 支持带有 TTL 的上限集合?

文档说: 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.

我认为没有,那么,有什么替代方法可以实现吗?

谢谢

4

0 回答 0