Class | Mongoid::Contexts::Mongo |
In: |
lib/mongoid/contexts/mongo.rb
|
Parent: | Object |
criteria | [RW] |
Aggregate the context. This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with counts.
@example Aggreate the context.
context.aggregate
@return [ Hash ] A Hash with field values as keys, counts as values
Get the average value for the supplied field.
This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with averages.
@example Get the average for a field.
context.avg(:age)
@param [ Symbol ] field The field to get the average for.
@return [ Numeric ] A numeric value that is the average.
Determine if the context is empty or blank given the criteria. Will perform a quick has_one asking only for the id.
@example Is the context empty?
context.blank?a
@return [ true, false ] True if blank.
Get the count of matching documents in the database for the context.
@example Get the count without skip and limit taken into consideration.
context.count
@example Get the count with skip and limit applied.
context.count(true)
@param [Boolean] extras True to inclued previous skip/limit
statements in the count; false to ignore them. Defaults to `false`.
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
Execute the context. This will take the selector and options and pass them on to the Ruby driver‘s +find()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned new documents of the type of class provided will be instantiated.
@example Execute the criteria on the context.
context.execute
Groups the context. This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with objects.
@example Get the criteria as a group.
context.group
@return [ Hash ] Hash with 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 results.
context.iterate { |doc| p doc }
Return the max value for a field.
This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with sums.
@example Get the max value.
context.max(:age)
@param [ Symbol ] field The field to get the max for.
@return [ Numeric ] A numeric max value.
Return the min value for a field.
This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with sums.
@example Get the min value.
context.min(:age)
@param [ Symbol ] field The field to get the min for.
@return [ Numeric ] A numeric minimum value.
Sum the context.
This will take the internally built selector and options and pass them on to the Ruby driver‘s +group()+ method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with sums.
@example Get the sum for a field.
context.sum(:age)
@param [ Symbol ] field The field who‘s values to sum.
@return [ Numeric ] A numeric value that is the sum.
Common functionality for grouping operations. Currently used by min, max and sum. Will gsub the field name in the supplied reduce function.
@example Execute the group function.
context.group(0, :avg, "")
@param [ Object ] start The value to start the map/reduce with. @param [ String ] field The field to aggregate. @param [ String ] reduce The reduce JS function.
@return [ Numeric ] A numeric result.
Get the options hash with the default sorting options provided.
@example Get the options.
criteria.options_with_default_sorting
@return [ Hash ] The options.
@since 2.3.2
Filters the field list. If no fields have been supplied, then it will be empty. If fields have been defined then _type will be included as well.
@example Process the field list.
context.process_options
@return [ Hash ] The options.