Piotr Kaluza
Piotr Kaluza

Reputation: 413

Keep track of attributes over time

I have a collection of Documents each having a "value" and I want to be able to track the value over time, my first idea is to create a snapshot of the document in before_save and then do a group_by {|t| t.created_at.hour} on those snapshots to create a line chart afterwards. This should work, any other ideas?

Upvotes: 0

Views: 101

Answers (1)

Sean Hill
Sean Hill

Reputation: 15056

The mongoid gem has a module called Mongoid::Versioning. Just include it in your model, like this:

class Person
  include Mongoid::Document
  include Mongoid::Versioning
end

That will give you access to all previous versions via @instance.versions.

http://mongoid.org/en/mongoid/docs/extras.html#versioning

Upvotes: 1

Related Questions