LoginSignup
1
1

More than 5 years have passed since last update.

容赦無いCollection Insert

Last updated at Posted at 2012-02-21

Mongodbに大量のデータをぶち込もうとすると、「Exceded maximum insert size of 16,000,000 bytes」などとエラーを吐くので、入るまで半分にしてねじ込み続ける容赦無いスクリプトを書いた。

def yousyanai_insert(data)
  begin
    NaotyModel.collection.insert(data)
  rescue
    data.each_slice(data.length / 2) {|half_data| yousyanai_insert(half_data) }
  end
end
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1