Class | Mongoid::Contexts::Enumerable |
In: |
lib/mongoid/contexts/enumerable/sort.rb
lib/mongoid/contexts/enumerable.rb |
Parent: | Object |
first | -> | one |
Get one document.
@example Get one document. context.one @return [ Document ] The first document in the array. |
collection | [RW] | |
criteria | [RW] |
Create the new enumerable context. This will need the selector and options from a Criteria and a documents array that is the underlying array of embedded documents from a has many association.
@example Create a new context.
Mongoid::Contexts::Enumerable.new(criteria)
@param [ Criteria ] criteria The criteria for the context.
Get the average value for the supplied field.
@example Get the average.
context.avg(:age)
@return [ Numeric ] A numeric value that is the average.
Delete all the documents in the database matching the selector.
@example Delete the documents.
context.delete_all
@return [ Integer ] The number of documents deleted.
@since 2.0.0.rc.1
Destroy all the documents in the database matching the selector.
@example Destroy the documents.
context.destroy_all
@return [ Integer ] The number of documents destroyed.
@since 2.0.0.rc.1
Enumerable implementation of execute. Returns matching documents for the selector, and adds options if supplied.
@example Execute the context.
context.execute
@return [ Array<Document> ] Documents that matched the selector.
Groups the documents by the first field supplied in the field options.
@example Group the context.
context.group
@return [ Hash ] Field values as keys, arrays of documents as values.
Iterate over each Document in the results. This can take an optional block to pass to each argument in the results.
@example Iterate over the documents.
context.iterate { |doc| p doc }
Get the largest value for the field in all the documents.
@example Get the max value.
context.max(:age)
@return [ Numeric ] The numerical largest value.
Get the smallest value for the field in all the documents.
@example Get the minimum value.
context.min(:age)
@return [ Numeric ] The numerical smallest value.
Get one document and tell the criteria to skip this record on successive calls.
@example Shift the documents.
context.shift
@return [ Document ] The first document in the array.
Filters the documents against the criteria‘s selector
@example Filter the documents.
context.filter
@return [ Array ] The documents filtered.
Set the collection to the collection of the root document.
@example Set the collection.
context.set_collection
@return [ Collection ] The root collection.