in lib/connectors/mongodb/connector.rb [79:138]
def yield_documents
with_client do |client|
cursor_type, cursor_with_options = create_db_cursor_on_collection(client[@collection])
cursor, options = cursor_with_options
case cursor_type
when FIND
skip = 0
found_overall = 0
overall_limit = Float::INFINITY
if options.present?
skip = options.fetch(:skip, skip)
overall_limit = options.fetch(:limit, overall_limit)
end
overall_limit_reached = false
loop do
found_in_page = 0
Utility::Logger.info("Requesting #{PAGE_SIZE} documents from MongoDB (Starting at #{skip})")
view = cursor.skip(skip).limit(PAGE_SIZE)
view.each do |document|
yield_with_handling_tolerable_errors do
yield serialize(document)
found_in_page += 1
found_overall += 1
overall_limit_reached = found_overall >= overall_limit && overall_limit != Float::INFINITY
end
break if overall_limit_reached
end
page_was_empty = found_in_page == 0
break if page_was_empty || overall_limit_reached
skip += PAGE_SIZE
end
when AGGREGATE
cursor.each do |document|
yield_with_handling_tolerable_errors do
yield serialize(document)
end
end
else
raise "Unknown retrieval function #{cursor_type} for MongoDB."
end
end
end