Method: MongoDoc::Contexts::Mongo#iterate

Defined in:
lib/mongo_doc/contexts/mongo.rb

#iterate(&block) ⇒ Object

Iterate over each Document in the results. This can take an optional block to pass to each argument in the results.

Example:

context.iterate { |doc| p doc }



143
144
145
146
147
148
149
150
# File 'lib/mongo_doc/contexts/mongo.rb', line 143

def iterate(&block)
  return caching(&block) if criteria.cached?
  if block_given?
    execute.each do |doc|
      yield doc
    end
  end
end