Batch insert/update using Mongoid?
You can use this:
books = [{:name => "Harry Potter"}, {:name => "Night"}] Book.collection.insert_many(books)
And I find that "insert" does not work for me(Monogoid 5.1.3):
NoMethodError: undefined method `insert' for # <Mongo::Collection:0x007fbdbc9b1cd0>Did you mean? insert_one insert_many inspect
This is the source code from "lib/mongo/collection.rb":
# Insert the provided documents into the collection.## @example Insert documents into the collection.# collection.insert_many([{ name: 'test' }])## @param [ Array<Hash> ] documents The documents to insert.# @param [ Hash ] options The insert options.## @return [ Result ] The database response wrapper.## @since 2.0.0def insert_many(documents, options = {}) inserts = documents.map{ |doc| { :insert_one => doc }} bulk_write(inserts, options)end