Versioned Documents for Mongoid4
Switch branches/tags
Nothing to show
Latest commit 1483514 Jul 9, 2014 @simi simi Fix mongoid link in
[ci skip]

Versioned documents for Mongoid4Build Status

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

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

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")



  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request