Module: Mongo::Collection::View::Iterable
- Includes:
- Mongo::CursorHost
- Included in:
- Mongo::Collection::View, Aggregation::Behavior
- Defined in:
- lib/mongo/collection/view/iterable.rb
Overview
Defines iteration related behavior for collection views, including cursor instantiation.
Instance Attribute Summary
Attributes included from Mongo::CursorHost
Instance Method Summary collapse
-
#close_query ⇒ nil
(also: #kill_cursors)
Cleans up resources associated with this query.
-
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by a query with this
View
.
Methods included from Mongo::CursorHost
Instance Method Details
#close_query ⇒ nil Also known as: kill_cursors
Note:
This method propagates any errors that occur when closing the server-side cursor.
Cleans up resources associated with this query.
If there is a server cursor associated with this query, it is closed by sending a KillCursors command to the server.
75 76 77 78 79 |
# File 'lib/mongo/collection/view/iterable.rb', line 75 def close_query if @cursor @cursor.close end end |
#each {|Each| ... } ⇒ Enumerator
Iterate through documents returned by a query with this View
.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mongo/collection/view/iterable.rb', line 43 def each @cursor = prefer_cached_cursor? ? cached_cursor : new_cursor_for_iteration return @cursor.to_enum unless block_given? limit_for_cached_query = compute_limit_for_cached_query # Ruby versions 2.5 and older do not support arr[0..nil] syntax, so # this must be a separate conditional. cursor_to_iterate = if limit_for_cached_query @cursor.to_a[0...limit_for_cached_query] else @cursor end cursor_to_iterate.each do |doc| yield doc end end |