The Mongoid :: Versioning module adds to the document a field with a name of type of type Integer, this field writes the version of the current document, starting from 1, to the maximum (if defined). In addition, you will have an embedded “version” document to be created. Then, the before_save callback is executed, which takes care of the version for you.
I would usually recommend the maximum, but that is up to you. As for how to get to them, it’s good that you didn’t submit a sample document, so release as a simple article:
This will give us a document something like this:
{ "title": "Hello World", "content": "Woo - content", "comments": [ ] "version": 2 "versions": [ { "title": "Hello World", "version": 1 } ] }
Now you just need to use standard search engines to get to it:
post = Post.find(:first, :conditions => {:title => "Hello World"})
Retrieve the latest version, and then you can programmatically search for previous versions. I would publish the conclusion, but at the moment I have no sample.
Similarly, you only need to run db.namespace.find () based on the header, the version field, if you want to do this through the shell.
Hope this makes sense.
source share