Method: Mongoid::Criteria::Queryable::Optional#limit

Defined in:
lib/mongoid/criteria/queryable/optional.rb

#limit(value = nil) ⇒ Optional

Add the number of documents to limit in the returned results.

Examples:

Limit the number of returned documents.

optional.limit(20)

Parameters:

  • value (Integer) (defaults to: nil)

    The number of documents to return.

Returns:



79
80
81
82
83
84
85
# File 'lib/mongoid/criteria/queryable/optional.rb', line 79

def limit(value = nil)
  option(value) do |options, query|
    val = value.to_i
    options.store(:limit, val)
    query.pipeline.push("$limit" => val) if aggregating?
  end
end