【发布时间】:2020-07-10 02:07:02
【问题描述】:
我希望我的收藏中的每个文档都有一个特定的过期时间。我一直在关注tutorial 和 this SO answer(但在 Python 中)。
这就是我创建索引的方式:
self.coll.create_index([('expireAt', 1)], expireAfterSeconds=0)
这是我要保存到 Mongo 的文档
document = {'_id': key, 'value': value, 'expireAt': expire_at}
self.coll.replace_one({'_id': key}, document, upsert=True)
我确实看到索引已创建,但我也可以看到应该删除的过期文档。
为什么?
编辑:有没有可能是因为集合是capped?
【问题讨论】:
标签: python python-3.x mongodb