Mongoid supports simple versioning through inclusion of the Mongoid::Versioning module. Including this module will create a versions embedded relation on the document that it will append to on each save. It will also update the version number on the document, which is an integer.
Add this line to your application's Gemfile:
gem 'mongoid-versioning', github: 'simi/mongoid-versioning'
And then execute:
class Person include Mongoid::Document include Mongoid::Versioning end
You can also set a max_versions setting, and Mongoid will only keep the max most recent versions.
class Person include Mongoid::Document include Mongoid::Versioning # keep at most 5 versions of a record max_versions 5 end
You may skip versioning at any point in time by wrapping the persistence call in a versionless block.
person.versionless do |doc| doc.update_attributes(name: "Theodore") end
- extracted from Mongoid by @simi
- errors fixed by awesome @gautamrege
- removed IdentityMap code by fabulous @deevis
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request