I include the Mongoid::Versioning module in my Mongoid based class. What's the best way to check the previous 'version' or incarnation of a document? I want to be able to see its history. This can be either through rails console
or MongoDB shell. What's the most easiest way to view the document history?
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How to represent an array with mixed types
The Mongoid::Versioning module adds a field named version of type Integer to the document, that field records the version of the current document, starting at 1, up to the maximum (if defined). In addition you will have an embedded document "versions" that will be created. There is then a before_save callback which takes care of the versioning for you.
Generally I would recommend a maximum, but that is up to you. In terms of how to get at them, well you didn't give an example document, so let's go with a very simple article as an example:
That will give us a document something like this:
Now you just need to use your standard find mechanisms to get to it:
Grab the latest version out of that, and then you can programmatically search for previous versions. I would post output, but I don't have a sample set up at the moment.
Similarly you need only run db.namespace.find() based on the title, version fields if you wish to do it via the shell.
Hopefully that makes sense.