Method: Mongo::Cursor#initialize
- Defined in:
- lib/mongo/cursor.rb
#initialize(collection, opts = {}) ⇒ Cursor
Create a new cursor.
Note: cursors are created when executing queries using [Collection#find] and other similar methods. Application developers shouldn’t have to create cursors manually.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mongo/cursor.rb', line 36 def initialize(collection, opts={}) @db = collection.db @collection = collection @connection = @db.connection @logger = @connection.logger @selector = opts[:selector] || {} @fields = convert_fields_for_query(opts[:fields]) @skip = opts[:skip] || 0 @limit = opts[:limit] || 0 @order = opts[:order] @hint = opts[:hint] @snapshot = opts[:snapshot] @timeout = opts.fetch(:timeout, true) @explain = opts[:explain] @socket = opts[:socket] @tailable = opts[:tailable] || false @closed = false @query_run = false batch_size(opts[:batch_size] || 0) @full_collection_name = "#{@collection.db.name}.#{@collection.name}" @cache = [] @returned = 0 if @collection.name =~ /^\$cmd/ || @collection.name =~ /^system/ @command = true else @command = false end end |