Method: Mongo::BulkWrite#initialize

Defined in:
lib/mongo/bulk_write.rb

#initialize(collection, requests, options = {}) ⇒ BulkWrite

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create the new bulk write operation.

Examples:

Create an ordered bulk write.

Mongo::BulkWrite.new(collection, [{ insert_one: { _id: 1 }}])

Create an unordered bulk write.

Mongo::BulkWrite.new(collection, [{ insert_one: { _id: 1 }}], ordered: false)

Create an ordered mixed bulk write.

Mongo::BulkWrite.new(
  collection,
  [
    { insert_one: { _id: 1 }},
    { update_one: { filter: { _id: 0 }, update: { '$set' => { name: 'test' }}}},
    { delete_one: { filter: { _id: 2 }}}
  ]
)

Parameters:

  • collection (Mongo::Collection)

    The collection.

  • requests (Enumerable<Hash, BSON::Document>)

    The requests, cannot be empty.

  • options (Hash, BSON::Document) (defaults to: {})

    The options.

Since:

  • 2.1.0



128
129
130
131
132
133
134
135
# File 'lib/mongo/bulk_write.rb', line 128

def initialize(collection, requests, options = {})
  @collection = collection
  @requests = requests
  @options = options || {}
  if @options[:timeout_ms] && @options[:timeout_ms] < 0
    raise ArgumentError, "timeout_ms options must be non-negative integer"
  end
end