2013-03-07 35 views
0

您好,我是rails和mongodb的學習者。我正在使用MongoDB作爲後端應用程序。 我有巨大的數據內容檢索單個請求時有錯誤是「光標錯誤」,因爲我使用的一個技巧是將所有數據分區爲小內容。對這一概念時遇到了一個錯誤,我的代碼是分離跳過和限制功能不能在rails rake文件中工作

 competitionsAry = NFL_Competition.where(sdi_sport_id: teamSdi_Sport_id) 

puts "Total competitions:" + competitionsAry.count.to_s // it has 2330 count on this step 

     execCount = competitionsAry.count/100 

     if competitionsAry.count % 100 != 0 

      execCount += 1 

     end  

     execCount.times do |ctr| 

     skipValue = ctr + 100 

     competitions = competitionsAry.skip(skipValue).limit(100) 

puts "Now the competition length is: " + competitions.length.to_s // here also same amount of 2330 data 

我知道「比賽= competitionsAry.skip(跳略值).limit(100)」這裏的問題。 跳過和限制功能不起作用。即使我試過「比賽= NFL_Competition.skip(skipValue).limit(100)」沒有結果什麼是例外任何人都可以幫助如何解決這個問題以及如何在rails上使用skip和limit函數。先謝謝你。

回答

0

雅我明白了,我在此使用紅寶石陣列切片概念。

competitions = competitionsAry[skipValue,100]