Moongoon::Collection::Versioning::Static
Instance methods
Clears the history collection.
NOTE: Use with caution!
Will remove all the versions in the history collection.
Counts the number of versions associated with a document that matches the id argument.
user_id = "123456"
User.count_versions user_id
Saves a copy of a document matching the id argument in the history collection and returns the id of the copy.
NOTE: similar to create_version.
Saves a copy with changes of a document matching the id argument in the history collection and returns the id of the copy.
NOTE: similar to create_version.
Finds all versions for a document matching has the id argument and returns an array of Moongoon::Collection instances.
NOTE: Versions are sorted by creation date.
user_id = "123456"
versions = User.find_all_versions user_id
Finds the latest version of a model by id and returns an instance of Moongoon::Collection.
Same syntax as Moongoon::Collection.find_by_id.
# "123456" is an _id in the original collection.
user_version = user.find_latest_version_by_id "123456"
Finds a specific version of a model by id and returns an instance of Moongoon::Collection.
Same syntax as Moongoon::Collection.find_by_id.
# "123456" is an _id in the history collection.
user_version = user.find_specific_version "123456"
NOTE: Similar to self.find_specific_version but will raise if the version is not found.
Finds one or more versions by their ids and returns an array of Moongoon::Collection instances.
NOTE: Versions are sorted by creation date in descending order.
names = ["John", "Jane"]
ids = names.map { |name|
user = User.new name: name
user.insert
user.create_version
}
# Contains one version for both models.
versions = User.find_specific_versions ids