Best way to loop over mongo collection?

I have a mongo collection in Rails where I use it this manner:

collection.find(selector, options).to_a

I have around 47K rows of data, and it seems very slow doing it this
way.

Should I be using the cursor instead of converting to an array? If so,
can anyone point me to the usage pattern? Or, is using to_a fine? Just
wondering if converting to an array is too slow.

On Tue, Feb 26, 2013 at 10:22 AM, Edward S. [email protected]
wrote:

I have a mongo collection in Rails where I use it this manner:

collection.find(selector, options).to_a

I have around 47K rows of data, and it seems very slow doing it this
way.

Should I be using the cursor instead of converting to an array? If so,
can anyone point me to the usage pattern? Or, is using to_a fine? Just
wondering if converting to an array is too slow.

How about you tell us what ODM you are using?

Jordon B. wrote in post #1099153:

On Tue, Feb 26, 2013 at 10:22 AM, Edward S. [email protected]
wrote:

I have a mongo collection in Rails where I use it this manner:

collection.find(selector, options).to_a

I have around 47K rows of data, and it seems very slow doing it this
way.

Should I be using the cursor instead of converting to an array? If so,
can anyone point me to the usage pattern? Or, is using to_a fine? Just
wondering if converting to an array is too slow.

How about you tell us what ODM you are using?

I’m not sure what ODM stands for. I’m using the standard ruby driver for
mongo; not MongoMapper or Mongoid.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs