Module | Mongoid::Criterion::Optional |
In: |
lib/mongoid/criterion/optional.rb
|
Tells the criteria that the cursor that gets returned needs to be cached. This is so multiple iterations don‘t hit the database multiple times, however this is not advisable when working with large data sets as the entire results will get stored in memory.
@example Flag the criteria as cached.
criteria.cache
@return [ Criteria ] The cloned criteria.
Adds fields to be sorted in descending order. Will add them in the order they were passed into the method.
@example Sort the criteria in descending order.
criteria.descending(:title, :dob) criteria.desc(:title, :dob)
@param [ Array<Symbol> ] fields The fields to sort on.
@return [ Criteria ] The cloned criteria.
Adds a criterion to the Criteria that specifies additional options to be passed to the Ruby driver, in the exact format for the driver.
@example Add extra params to the criteria.
criteria.extras(:limit => 20, :skip => 40)
@param [ Hash ] extras The extra driver options.
@return [ Criteria ] The cloned criteria.
Adds a criterion to the Criteria that specifies an id that must be matched.
@example Add a single id criteria.
criteria.for_ids("4ab2bc4b8ad548971900005c")
@example Add multiple id criteria.
criteria.for_ids(["4ab2bc4b8ad548971900005c", "4c454e7ebf4b98032d000001"])
@param [ Array ] ids: A single id or an array of ids.
@return [ Criteria ] The cloned criteria.
Adds a criterion to the Criteria that specifies the maximum number of results to return. This is mostly used in conjunction with skip() to handle paginated results.
@example Limit the result set size.
criteria.limit(100)
@param [ Integer ] value The max number of results.
@return [ Criteria ] The cloned criteria.
Adds a criterion to the Criteria that specifies the sort order of the returned documents in the database. Similar to a SQL "ORDER BY".
@example Order by specific fields.
criteria.order_by([[:field1, :asc], [:field2, :desc]])
@param [ Array ] params: An Array of [field, direction] sorting pairs.
@return [ Criteria ] The cloned criteria.
Adds a criterion to the Criteria that specifies how many results to skip when returning Documents. This is mostly used in conjunction with limit() to handle paginated results, and is similar to the traditional "offset" parameter.
@example Skip a specified number of documents.
criteria.skip(20)
@param [ Integer ] value The number of results to skip.
@return [ Criteria ] The cloned criteria.