Answer the question
In order to leave comments, you need to log in
How to implement document aging in MogonDB?
There is a collection of documents in mongo, which are, say, orders in an online store.
{"_id": ..., "status": "new", "expiring_at": 2018-02-04 23:40:40.493Z}
if err := col.Find(query).All(items); err != nil {
return fmt.Errorf("unable to search expired orders: %s", err)
}
for _, item := range *items {
if err := item.Expire(); err != nil {
return fmt.Errorf("unable to mark the order as expired: %s", err)
}
item.Version++
if err := col.Update(bson.M{"_id": item.ID, "version": item.Version - 1}, &item); err != nil {
return fmt.Errorf("unable to store expired order: %s. possible a concurrent access issue", err)
}
}
return nil
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question