Any packages or strategies for keeping track of changes to documents (updates)?

Hi all, I was wondering if there are any community-standard approaches or packages for keeping track of changes to documents, eg: which fields were changed, when and by whom etc?

Currently I’m looking at doing this manually either in a collection hook or in method calls but would be interested to see how others are approaching it.

The end goal here is to be able to display a document’s history to a user, eg: last 10 changes.

Thanks

We do keep a history of changes inside the document, but only for a couple of fields, and only for a single collection, as this is not a proper way of tracking / auditing changes.

For something more evolved, I’d suggest Vermongo, with a package for Meteor available here: https://github.com/micktaiwan/meteor-vermongo

You might need to fork and maintain it if it’s not up to date.

Vermongo stores whole copies. Alternatively, use an approach based on a single collection where you store changes, perhaps with a TTL index so it doesn’t grow too big. You could use a diffing approach, with someone having taken care of this for you already: https://github.com/benjamine/jsondiffpatch

1 Like

Thanks for the reply. Seems really interesting but maybe perhaps a more serious project than I require.

I stumbled upon https://github.com/simonsimcity/meteor-collection-revisions/ which stores whole copies of documents and allows for restoration (which is pretty cool).

That would be really useful for “proper” versioning, maybe I’ll just implement a simple array of objects that I trigger on various updates: John Smith marked this issue as complete with a date etc

1 Like

If that’s all you need, then by all means, an array with a few objects should do the trick. A proper versioning system would be overkill

1 Like

We do it via array field in doc.

task {
   _id
   title
   ...
   activity [{
      userId    //who
      type      //what
      date      //when
      extraData //additional information, e.g. new task's title
   }]
}

It is very simple solution. But, if you want to get old version, you should store previous values of fields.

1 Like

Thanks, I think for the current app, just a generic, “somebody did x” is great, maybe on more complex apps a full revision system would be cool