nurb
nurb

Reputation: 333

Database structure for MongoDB realisation of saving changes of objects in history

I would like to save the information about some objects and relations between them in Mongodb. There is also requirement to save all changes objects in history and ability to look the state of the objects in the past.
Now I'm saving actual version of objects in respective collections and using separate respective collections for changes (with id of objects and change time), and collecting the state of objects in the past by using all changes by time.
I'm feeling that I'm inventing bicycle here and there is better database structure or existing framework to do this easier. Can someone recommend something? Will be very obliged, thank you.

Upvotes: 0

Views: 1234

Answers (1)

helmy
helmy

Reputation: 9497

This is commonly referred to as "versioning" or "document versioning". The most common approaches are:

  1. Store a full document for each write, in the same collection, using some scheme to determine which version is "current"
  2. Store a full document for each write, with the "current" version in one collection and older versions in a separate collection
  3. Store all document versions inside a single document
  4. Store only deltas (changes) for each version

Each approach has it's own set of advantages and tradeoffs. Here are some good resource with further exploration of these approaches:

I am not aware of any popular frameworks that handle this in Java, and this may also be dependent on whether or not you are using an ODM (e.g. Spring Data MongoDB or Morphia). Mongooose (Node.js) does have document versioning.

Upvotes: 1

Related Questions