Class: Mongo::Cursor
- Inherits:
-
Object
- Object
- Mongo::Cursor
- Extended by:
- Forwardable
- Includes:
- Enumerable, Retryable
- Defined in:
- lib/mongo/cursor.rb,
lib/mongo/cursor/builder/op_get_more.rb,
lib/mongo/cursor/builder/op_kill_cursors.rb,
lib/mongo/cursor/builder/get_more_command.rb,
lib/mongo/cursor/builder/kill_cursors_command.rb
Overview
The Cursor
API is semipublic.
Client-side representation of an iterator over a query result set on the server.
A Cursor
is not created directly by a user. Rather, CollectionView
creates a Cursor
in an Enumerable module method.
Defined Under Namespace
Modules: Builder
Constant Summary
Constants included from Retryable
Retryable::COULD_NOT_CONTACT_PRIMARY, Retryable::NOT_MASTER
Instance Attribute Summary collapse
-
#view ⇒ Collection::View
readonly
View The collection view.
Instance Method Summary collapse
-
#batch_size ⇒ Integer
Get the batch size.
-
#closed? ⇒ true, false
Is the cursor closed?.
-
#collection_name ⇒ String
Get the parsed collection name.
-
#each ⇒ Enumerator
Iterate through documents returned from the query.
-
#id ⇒ Integer
Get the cursor id.
-
#initialize(view, result, server) ⇒ Cursor
constructor
Creates a
Cursor
object. -
#inspect ⇒ String
Get a human-readable string representation of
Cursor
. -
#to_return ⇒ Integer
Get the number of documents to return.
Methods included from Retryable
#read_with_retry, #write_with_retry
Constructor Details
#initialize(view, result, server) ⇒ Cursor
Creates a Cursor
object.
55 56 57 58 59 60 |
# File 'lib/mongo/cursor.rb', line 55 def initialize(view, result, server) @view = view @server = server @initial_result = result @remaining = limit if limited? end |
Instance Attribute Details
#view ⇒ Collection::View (readonly)
Returns view The collection view.
43 44 45 |
# File 'lib/mongo/cursor.rb', line 43 def view @view end |
Instance Method Details
#batch_size ⇒ Integer
Get the batch size.
100 101 102 |
# File 'lib/mongo/cursor.rb', line 100 def batch_size @view.batch_size && @view.batch_size > 0 ? @view.batch_size : limit end |
#closed? ⇒ true, false
Is the cursor closed?
112 113 114 |
# File 'lib/mongo/cursor.rb', line 112 def closed? !more? end |
#collection_name ⇒ String
Get the parsed collection name.
124 125 126 |
# File 'lib/mongo/cursor.rb', line 124 def collection_name @coll_name || collection.name end |
#each ⇒ Enumerator
Iterate through documents returned from the query.
84 85 86 87 88 89 90 |
# File 'lib/mongo/cursor.rb', line 84 def each process(@initial_result).each { |doc| yield doc } while more? return kill_cursors if exhausted? get_more.each { |doc| yield doc } end end |
#id ⇒ Integer
A cursor id of 0 means the cursor was closed on the server.
Get the cursor id.
138 139 140 |
# File 'lib/mongo/cursor.rb', line 138 def id @cursor_id end |
#inspect ⇒ String
Get a human-readable string representation of Cursor
.
70 71 72 |
# File 'lib/mongo/cursor.rb', line 70 def inspect "#<Mongo::Cursor:0x#{object_id} @view=#{@view.inspect}>" end |
#to_return ⇒ Integer
Get the number of documents to return. Used on 3.0 and lower server versions.
151 152 153 |
# File 'lib/mongo/cursor.rb', line 151 def to_return use_limit? ? @remaining : (batch_size || 0) end |