简体   繁体   中英

Mongodb server. How to automatically change the status is expired when expired

In mongodb I have a collection (user), where there is 2 information is status and expiry (date). How to automatically change the status is expired when expired at database server. Thanks

You can automatically delete documents using TTL indexes if that helps and/or listen/react to changes using change streams which have also been widely discussed here: How to listen for changes to a MongoDB collection?

Above and beyond this, however, there's nothing built into MongoDB at this stage that could be used to achieve this kind of behaviour so you will have to build something yourself using eg an external scheduler that runs an update command on a regular basis setting the desired values on the right documents.

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