Method: XGen::Mongo::Driver::Collection#find
- Defined in:
- lib/mongo/collection.rb
#find(selector = {}, options = {}) ⇒ Object
Return records that match a selector hash. See Mongo docs for details.
Options:
- :fields
-
Array of collection field names; only those will be returned (plus _id if defined)
- :offset
-
Start at this record when returning records
- :limit
-
Maximum number of records to return
- :sort
-
Either hash of field names as keys and 1/-1 as values; 1 == ascending, -1 == descending, or array of field names (all assumed to be sorted in ascending order).
- :hint
-
See #hint. This option overrides the collection-wide value.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mongo/collection.rb', line 52 def find(selector={}, ={}) fields = .delete(:fields) fields = nil if fields && fields.empty? offset = .delete(:offset) || 0 limit = .delete(:limit) || 0 sort = .delete(:sort) hint = .delete(:hint) if hint hint = normalize_hint_fields(hint) else hint = @hint # assumed to be normalized already end raise RuntimeError, "Unknown options [#{.inspect}]" unless .empty? @db.query(self, Query.new(selector, fields, offset, limit, sort, hint)) end |