search

Home  >  Q&A  >  body text

Database - How should a limited-time history table be designed?

The database is MongoDB.

Suppose there is a data table (data collection-collection) --- Users.

Every time a user (User) updates his or her data, a copy of historical data needs to be retained, but not too much. For example, only the latest 5 copies can be saved at most.

If you design a table UserHistory to store old data, you need to check whether there are more than 5 records each time you save new records. If so, delete the oldest one.

Is this reasonable?

Is there a more reasonable design?

ringa_leeringa_lee2759 days ago1070

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-31 10:38:04

    https://docs.mongodb.com/v3.0...
    Can this document answer your questions?

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-31 10:38:04

    Traditionally use triggers + stored procedures.

    reply
    0
  • Cancelreply