module Moongoon::Collection::Versioning::Static
Defined in:
models/models.crInstance Method Summary
-
#clear_history : Nil
Clears the history collection.
-
#count_versions(id, query = BSON.new, **args) : Int32 | Int64
Counts the number of versions associated with a document that matches the id argument.
-
#create_version_by_id(id) : String | Nil
Saves a copy of a document matching the id argument in the history collection and returns the id of the copy.
-
#create_version_by_id(id, &block : self -> self) : String | Nil
Saves a copy with changes of a document matching the id argument in the history collection and returns the id of the copy.
-
#find_all_versions(id, query = BSON.new, fields = nil, skip = 0, limit = 0, order_by = {_id: -1}, **args) : Array(self)
Finds all versions for a document matching has the id argument and returns an array of
Moongoon::Collection
instances. -
#find_latest_version_by_id(id, fields = nil, **args) : self | Nil
Finds the latest version of a model by id and returns an instance of
Moongoon::Collection
. -
#find_specific_version(id, query = BSON.new, fields = nil, skip = 0, **args) : self | Nil
Finds a specific version of a model by id and returns an instance of
Moongoon::Collection
. -
#find_specific_version!(id, **args) : self
NOTE Similar to
self.find_specific_version
but will raise if the version is not found. -
#find_specific_versions(ids, query = BSON.new, fields = nil, skip = 0, limit = 0, order_by = {_id: -1}, **args) : Array(self)
Finds one or more versions by their ids and returns an array of
Moongoon::Collection
instances.
Instance Method Detail
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