使用 Mongoid 批量插入/更新?
问题描述:
我用谷歌搜索了所有其他人,但没有找到答案.问题是:
I googled and all others, but I didn't find the answer. The question is:
如何使用 Mongoid 批量插入 MongoDB?
Hi, how can I do batch insert with Mongoid to MongoDB?
答
您可以使用 ruby mongo 驱动程序的 insert 方法插入一批散列数组.从任何 Mongoid 类,您都可以调用 collection 来访问它.
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)