Method: Mongoid::Collection#insert

Defined in:
lib/mongoid/collection.rb

#insert(documents, options = {}) ⇒ Object

Inserts one or more documents in the collection.

Examples:

Insert documents.

collection.insert(
  { "field" => "value" },
  :safe => true
)

Parameters:

  • documents (Hash, Array<Hash>)

    A single document or multiples.

  • options (Hash) (defaults to: {})

    The options.

Since:

  • 2.0.2, batch-relational-insert



93
94
95
96
97
98
99
100
# File 'lib/mongoid/collection.rb', line 93

def insert(documents, options = {})
  consumer = Threaded.insert
  if consumer
    consumer.consume(documents, options)
  else
    master(options).insert(documents, options)
  end
end