mongodb - mass insert mongoid -


i have web app on heroku takes plain text of comma separated values (or other delimiter separated values) user copies-and-pastes web form, , app data each line , save mongo db.

for instance

45nm, 180, 3 44nm, 180, 3.5 45nm, 90, 7 ...  @project = project.first # project embeds_many :simulations @array_of_array_of_data_from_csv.each |line|   @project.simulations.create(:thick => line[0], :ang => line[1], :pro => line[2])   #e.g. line[0] => 45nm, line[1] => 180, line[2] => 3 end 

for app's purposes, can't let user kind of import, have data them textarea. , each time, user can paste upto 30,000 lines. tried doing (30,000 data points) on heroku fake data in console, terminated saying long processes not supported in console, try rake tasks instead.

so wondering if knows either way takes long insert 30,000 documents (of course, can that's the way is), or knows way speedily insert 30,000 documents?

thanks help

if inserting many documents should doing batch ... routinely insert 200,000 document batches , created in snap!

so, instead of making loop "creates" / inserts new document each time have loop append array of documents , insert mongodb 1 big batch.

an example of how mongoid can found in question.

however should keep in mind might end being memory intensive (as whole array of hashes/documents in memory build it.)

just careful :)


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -