Skip to content

Instantly share code, notes, and snippets.

@SQiShER
Created August 31, 2012 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SQiShER/3555555 to your computer and use it in GitHub Desktop.
Save SQiShER/3555555 to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment