質問

I am using ruby 1.9.3 with the twitter and mongo gems.

I have the following code working:

Twitter.user_timeline("GSElevator", :count => 200, :exclude_replies => "true", :include_rts => "false").each do |r| rawtest.insert(r.attrs) end

My currently method of looping through each enumerable and then inserting the attrs, one by one, proves to be relatively slow. How can I insert the 200 enumerables in a single, quick batch?

Thanks in advance for the help.

役に立ちましたか?

解決

You can pass an array of documents to the insert method:

rawtest.insert(Twitter.user_timeline("GSElevator", params).map(&:attrs))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top