lib/mongo/collection/view/iterable.rb
# Iterate through documents returned by a query with this +View+.
#
# @example Iterate through the result of the view.
#   view.each do |document|
#     p document
#   end
#
# @return [ Enumerator ] The enumerator.
#
# @since 2.0.0
#
# @yieldparam [ Hash ] Each matching document.
Iterate through documents returned by a query with this +View+.
Iterate through documents returned by a query with this + View + .
def each
          @cursor = if use_query_cache? && cached_cursor
            cached_cursor
          else
            session = client.send(:get_session, @options)
            select_cursor(session)
          end
          if use_query_cache?
            QueryCache.set(@cursor, **cache_options) unless cached_cursor
            limit_for_cached_query = respond_to?(:limit) ? limit : nil
          end
          if block_given?
            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
          else
            @cursor.to_enum
          end
        end
def each @cursor = if use_query_cache? && cached_cursor cached_cursor else session = client . send ( :get_session , @options ) select_cursor ( session ) end if use_query_cache? QueryCache . set ( @cursor , ** cache_options ) unless cached_cursor limit_for_cached_query = respond_to? ( :limit ) ? limit : nil end if block_given? 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 else @cursor . to_enum end end
Iterate through documents returned by a query with this +View+.
Iterate through documents returned by a query with this + View + .
# No need to store the cursor in the query cache if there is # already a cached cursor stored at this key. # If a query with a limit is performed, the query cache will # re-use results from an earlier query with the same or larger # limit, and then impose the lower limit during iteration. # Ruby versions 2.5 and older do not support arr[0..nil] syntax, so # this must be a separate conditional.
None
 Enumerator 
<not_specific>
Each matching document.
Each matching document .
example
Iterate through the result of the view. view.each do |document| p document end
Iterate through the result of the view . view . each do |document| p document end
since
None