MongoDb TTL on nested document is possible?

天涯浪子 提交于 2019-12-01 16:15:00

That is currently not possible with TTL index. Mongod will remove the whole document after a specified number of seconds or at a specific clock time.

TTL relies on a background thread in mongod that reads the date-typed values in the index and removes expired documents from the collection.

I would recommend that you store the session sub-document in a separate collection and add a TTL index on that collection.

If you can't change your schema, the alternative is to create a background job that will delete nested documents from your collection every 60 seconds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!