hiddentao / robe

MongoDB ODM for Node.js using ES6 generators. Supports schema validation, raw querying, oplog tailing, etc.
http://hiddentao.github.io/robe
MIT License
177 stars 12 forks source link

Sample for Bulk Inserting to mongodb #5

Closed thiyaga123 closed 9 years ago

thiyaga123 commented 9 years ago

Just noob question. Can you please give me sample code to "bulk insert" multiple docs.

hiddentao commented 9 years ago

There is no built-in method but you could do this:

var collection = db.collection('scores');

var docsToInsert = < array of documents to insert >;

yield docsToInsert.map(function(doc) {
   return collection.insert(doc);
})
thiyaga123 commented 9 years ago

Thank you.. But , i dont think , this is optimized of millions of inserts..

Any other way.

hiddentao commented 9 years ago

I'm afraid not. If the data you wish to insert is readily available in a file you might be better of running a script from the command-line using the mongo command-line tool.