| 创建 | createIndex({ expireAt: 1 }, { expireAfterSeconds: 3600 }) |
|---|---|
| 调整 | collMod 修改 expireAfterSeconds |
| 机制 | 后台线程约每 60 秒轮询一次,删除是异步的 |
创建与调整
创建与调整
db.sessions.createIndex({ expireAt: 1 }, { expireAfterSeconds: 3600 })
db.runCommand({ collMod: "sessions", index: { keyPattern: { expireAt: 1 }, expireAfterSeconds: 7200 } })过期时间基于字段值换算,字段必须是日期类型(或日期数组,按其中最早时间处理)。