Tuesday, May 11, 2010

MongoDB Ruby Driver : nToReturn=100?

The other day I noticed in my logs that I kept getting my very large (6 million rows) result set back 100 rows at a time.  The log kept saying getmore, getmore, getmore… with nToReturn=100 set as a parameter.  So it was doing the right thing, but where was that 100 coming from?

A post on the user group gave me the answer – the default “batch_size” option for find is set at 100 in my version of the Ruby driver, when it should be set at o (which is the signal for the driver to just figure out the optimal size).  So you can override this by forcing batch_size:

@results = @objects.find(@conditions, {:batch_size=>0})

You should notice an improvement in performance.

No comments: