1

I have a code which gets all the records from a collection of a mongodb and then it performs some computations.

My program takes too much time as the "coll_id.find().each do |eachitem|......." returns only 300 records at an instant.

If I place a counter inside the loop and check it prints 300 records and then sleeps for around 3 to 4 seconds before printing the counter value for next set of 300 records..

coll_id.find().each do |eachcollectionitem|
    puts "counter value for record " + counter.to_s
    counter=counter +1 
            ---- My computations here ----- 
    end

Is this a limitation of ruby-mongodb api or some configurations needs to be done so that the code can get access to all the records at one instant.

1 Answers1

0

How large are your documents? It's possible that the deseriaization is taking a long time. Are you using the C extensions (bson_ext)?

You might want to try passing a logger when you connect. That could help sort our what's going on. Alternatively, can you paste in the MongoDB log? What's happening there during the pause?

Kyle Banker
  • 4,359
  • 23
  • 18