public
Created

  • Download Gist
gistfile1.md
Markdown

I'm afraid the paths you are storing in MongoDB won't be very useful, since they are simply the default toString() representation of the referenced collection item. In order to use this path to access the property via java-object-diff, you'd need to be able to deserialize it to an actual instance of an object that has the same identity (equals == true) as the one you want to reference.

There are ways to do that, like writing a custom serializer for the PropertyPath to serialize a deserializable version of the reference item, but that leads to pretty verbose JSON and is rather fragile.

I personally don't recommend storing the diff in a database, but rather compare two document versions on demand. Depending on your scenario that may or may not cause performance issues. If it does, there are usually ways to cache the information you actually need, without storing the entire diff in the database.

I once had the same problem when I tried to generate a Github-like activity stream. I first approached it by storing the diff in CouchDB, but that turned out to be incredibly verbose, hard to maintain an even harder to keep backwards-compatible. So I ended up keeping earlier versions of my documents in the database and use java-object-diff to detect changes every time I save a new version. I then use the diff to convert the changes into more generic activity stream items and store those in an ElasticSearch index.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.