Ruby map/collect is slow on a large Mongoid collection -


I have a casual collection on which I run where query.

Now, I want to create an array with the value of a specific field from all the documents present in the archive.

For example if I have a monogid model

  square fu field: color, type: string end  

let me do something like this -

  red_ducks = Foo.where (color: 'red') red_duck_ids = red_ducks.map (& amp;: _ id)  

Unfortunately , When the result of the query is large it takes a lot of time. For example, in my case, 10,000 documents take 6 seconds.

Is there any way to speed up this speed?

Can not you just call different calls to your circle with _id as a property?

red_duck_ids = Foo.where (color: 'red'). Specific (: _ID)

will return a list of all the _id that meet your conditions and more information on you.

You can also see and you can use it if you are using version 3.1 or newer.


Comments

Popular posts from this blog

c++ - ERROR: cannot open source file x11\xlib.h -

c - What are pthread cancelation points used for? -

c# - Show a huge number of data in DevExpress GridView -