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.
Asked
Active
Viewed 1,133 times
0

nurb
- 325
- 3
- 6
1 Answers
1
This is commonly referred to as "versioning" or "document versioning". The most common approaches are:
- Store a full document for each write, in the same collection, using some scheme to determine which version is "current"
- Store a full document for each write, with the "current" version in one collection and older versions in a separate collection
- Store all document versions inside a single document
- 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:
- How to Track Versions with MongoDB
- Ways to implement data versioning in MongoDB
- Java MongoDB Object Versioning
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.