Batch insert/update using Mongoid?

Autodidact picture Autodidact · Sep 22, 2010 · Viewed 20k times · Source

I googled and all others, but I didn't find the answer. The question is:

Hi, how can I do batch insert with Mongoid to MongoDB?

Answer

tommy chheng picture tommy chheng · Oct 22, 2010

You can insert a batch array of hashes using the ruby mongo driver's insert method. From any Mongoid class, you can call collection to access it.

batch = [{:name => "mongodb"}, {:name => "mongoid"}]  
Article.collection.insert(batch)