使用Mongoid批量插入/更新? [英] Batch insert/update using Mongoid?
本文介绍了使用Mongoid批量插入/更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用Google搜索了所有其他搜索,但没有找到答案.问题是:
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)
这篇关于使用Mongoid批量插入/更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文