Module: Mongo::Collection::View::Iterable
- Included in:
- Mongo::Collection::View, Aggregation
- Defined in:
- lib/mongo/collection/view/iterable.rb
Overview
Defines iteration related behaviour for collection views, including cursor instantiation.
Instance Method Summary collapse
-
#close_query ⇒ Object
Stop the iteration by sending a KillCursors command to the server.
-
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by a query with this
View
.
Instance Method Details
#close_query ⇒ Object
Stop the iteration by sending a KillCursors command to the server.
56 57 58 |
# File 'lib/mongo/collection/view/iterable.rb', line 56 def close_query @cursor.send(:kill_cursors) if @cursor && !@cursor.closed? end |
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by a query with this View
.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mongo/collection/view/iterable.rb', line 37 def each @cursor = nil read_with_retry do server = read.select_server(cluster, false) result = send_initial_query(server) @cursor = Cursor.new(view, result, server) end @cursor.each do |doc| yield doc end if block_given? @cursor.to_enum end |