简体   繁体   中英

MongoDB TTL Collection

我有一个具有“ createdAt”日期的标记集合,mongo每小时都会为我过期,还有一个“用户”集合,其中每个用户都有他们设置的标记的ObjectId列表,有什么我可以删除的方法MongoDB使标记过期时,用户标记列表中的标记ID?

Quoting TTL Index - Delete Operations

A background thread in mongod reads the values in the index and removes expired documents from the collection.

When the TTL thread is active, you will see delete operations in the output of db.currentOp() or in the data collected by the database profiler.

There doesn't seem to be any way to hook into the process.

What you could do though is stop keeping list of Markers on the user side and instead keep a user ID in a marker itself (and add appropriate index depending on how will you store the reference and query for it). This way you'll have quick way to retrieve user's Markers and won't need to worry about stale entries in the list at a cost of an additional query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM