Ways to implement data versioning in MongoDB -
can share thoughts how implement data versioning in mongodb. (i've asked similar question regarding cassandra. if have thoughts db better please share)
suppose need version records in simple address book. (address book records stored flat json objects). expect history:
- will used infrequently
- will used @ once present in "time machine" fashion
- there won't more versions few hundred single record. history won't expire.
i'm considering following approaches:
create new object collection store history of records or changes records. store 1 object per version reference address book entry. such records looks follows:
{ '_id': 'new id', 'user': user_id, 'timestamp': timestamp, 'address_book_id': 'id of address book record' 'old_record': {'first_name': 'jon', 'last_name':'doe' ...} }
this approach can modified store array of versions per document. seems slower approach without advantages.
store versions serialized (json) object attached address book entries. i'm not sure how attach such objects mongodb documents. perhaps array of strings. (modelled after simple document versioning couchdb)
the first big question when diving in "how want store changesets"?
- diffs?
- whole record copies?
my personal approach store diffs. because display of these diffs special action, put diffs in different "history" collection.
i use different collection save memory space. don't want full history simple query. keeping history out of object can keep out of commonly accessed memory when data queried.
to make life easy, make history document contain dictionary of time-stamped diffs. this:
{ _id : "id of address book record", changes : { 1234567 : { "city" : "omaha", "state" : "nebraska" }, 1234568 : { "city" : "kansas city", "state" : "missouri" } } }
to make life easy, make part of dataobjects (entitywrapper, whatever) use access data. these objects have form of history, can override save()
method make change @ same time.
update: 2015-10
it looks there a spec handling json diffs. seems more robust way store diffs / changes.
Comments
Post a Comment