【发布时间】:2014-11-15 05:31:25
【问题描述】:
从我的 Ruby on Rails 应用程序中,我需要将 Customer 文档插入 MongoDB。出于性能原因,我需要批量插入它们:
Customer.collection.insert([{mail_address: "hello_1@hello_1.com"}, {mail_address: "hello_2@hello_2.com"}])
我有一个索引来强制 mail_address 属性的唯一性:
index({ mail_address: 1 }, { background: true, unique: true })
但这意味着如果一个失败,整个批次都会失败。
如何批量插入文档,只失败/拒绝重复的文档?
【问题讨论】:
标签: ruby-on-rails mongodb mongoid