Method: Mongo::Query#initialize

Defined in:
lib/mongo/query.rb

#initialize(sel = {}, return_fields = nil, number_to_skip = 0, number_to_return = 0, order_by = nil, hint = nil, snapshot = nil) ⇒ Query

sel

A hash describing the query. See the Mongo docs for details.

return_fields

If not nil, a single field name or an array of field names. Only those fields will be returned. (Called :fields in calls to Collection#find.)

number_to_skip

Number of records to skip before returning records. (Called :offset in calls to Collection#find.) Default is 0.

number_to_return

Max number of records to return. (Called :limit in calls to Collection#find.) Default is 0 (all records).

order_by

If not nil, specifies record sort order. May be a String, Hash, OrderedHash, or Array. If a string, the results will be ordered by that field in ascending order. If an array, it should be an array of field names which will all be sorted in ascending order. If a hash, it may be either a regular Hash or an OrderedHash. The keys should be field names, and the values should be 1 (ascending) or -1 (descending). Note that if it is a regular Hash then sorting by more than one field probably will not be what you intend because key order is not preserved. (order_by is called :sort in calls to Collection#find.)

hint

If not nil, specifies query hint fields. Must be either

+nil+ or a hash (preferably an OrderedHash). See
Collection#hint.


64
65
66
67
68
69
70
# File 'lib/mongo/query.rb', line 64

def initialize(sel={}, return_fields=nil, number_to_skip=0, number_to_return=0, order_by=nil, hint=nil, snapshot=nil)
  @number_to_skip, @number_to_return, @order_by, @hint, @snapshot =
    number_to_skip, number_to_return, order_by, hint, snapshot
  @explain = nil
  self.selector = sel
  self.fields = return_fields
end