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
(also: #kill_cursors)
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 Also known as: kill_cursors
Stop the iteration by sending a KillCursors command to the server.
57 58 59 |
# File 'lib/mongo/collection/view/iterable.rb', line 57 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 49 |
# File 'lib/mongo/collection/view/iterable.rb', line 37 def each @cursor = nil session = client.send(:get_session, ) read_with_retry(session) do server = server_selector.select_server(cluster) result = send_initial_query(server, session) @cursor = Cursor.new(view, result, server, session: session) end @cursor.each do |doc| yield doc end if block_given? @cursor.to_enum end |