我正在尝试使用ming ODM 映射器确保我的集合过期超过 2 周的文档:
class SloData(MappedClass):
class __mongometa__:
session = session
name = 'slo_data'
indexes = ['application']
custom_indexes = [
# expire records after two weeks
dict(fields=('datetime',), expireAfterSeconds=14*24*60*60)
]
_id = FieldProperty(schema.ObjectId)
datetime = FieldProperty(schema.DateTime)
value = FieldProperty(str)
application = RelationProperty('SloApplication')
def ensure_indexes():
for mapper in ming.odm.Mapper.all_mappers():
session.ensure_indexes(mapper.collection)
但是当我删除集合并重新确保索引时,没有设置 expireAfterSeconds 索引:
{
"v" : 1,
"key" : {
"datetime" : 1
},
"ns" : "performance.slo_data",
"name" : "datetime_1",
"background" : true,
"sparse" : false
}