使用 Mongoid 批量插入/更新? [英] Batch insert/update using Mongoid?

查看:35
本文介绍了使用 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)

这篇关于使用 Mongoid 批量插入/更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆