I'm currently use Mongoid to talk to my mongodb database. I have a query like the following:
ClassDoc.only(:class_id).where(:recurrs => true)
I'm only interested in the IDs as I exclude them in a subsequent query. However, the subsequent query needs the IDs in an array so I have to do this:
first_result_ids = ClassDoc.only(:class_id).where(:recurrs => true).collect { |class| class.class_id }
This takes quite a long time since AFAIK 'collect' loops over every result. It can take up to 10s to loop over just 1000 results.
Is there a way to pull the IDs out directly into an array?