What happens to a document in a TTL index when it expires? Choose the best answer:
Answer options
- A.It will remain in the collection until the next time it is read, at which point it will be automatically removed instead of returned
- B.It will remain in the collection until the next time it is read, at which point it will be present in the first cursor returned, but automatically removed afterwards
- C.It will be present in the cursors returned by queries until eventually being removed by a background task that runs periodically
- D.It will no longer show up in queries, but will remain in the collection until eventually being removed by a background task that runs periodically
- E.It will be removed immediately
Answer confidence: High
Correct answer: C
Explanation language: Chinese
TTL 索引不会在查询时把过期文档过滤掉:后台 TTL 线程约每 60 秒扫一次并删除到期文档,在真正删除之前文档仍会被查询和游标返回,所以 D 对。C 的"不再出现在查询中"是最有迷惑性的错误项——MongoDB 没有"逻辑过期"这种语义。