gemを使用する場合Moped
、ハッシュの配列を次のように格納できます。
users = [{username: "ben", password: "123456", type: "admin" }, {username: "joe", password: "abcd1234" }]
Mongoid::Sessions.default["collection"].insert(users)
Mongoid ドキュメントでは、次のようになります。
class User
field :username, type: String
field :password, type: String
end
users.each { |user_hash| User.create(user_hash) }
これは、それぞれの挿入操作を意味します。シングルオペレーション方式を維持する方法をご存知ですか?での取引のようなものでしょActiveRecord
うか?