Class: Mongo::BulkWrite
- Inherits:
-
Object
- Object
- Mongo::BulkWrite
- Extended by:
- Forwardable
- Includes:
- Operation::ResponseHandling
- Defined in:
- lib/mongo/bulk_write.rb,
lib/mongo/bulk_write/result.rb,
lib/mongo/bulk_write/combineable.rb,
lib/mongo/bulk_write/validatable.rb,
lib/mongo/bulk_write/transformable.rb,
lib/mongo/bulk_write/result_combiner.rb,
lib/mongo/bulk_write/ordered_combiner.rb,
lib/mongo/bulk_write/unordered_combiner.rb
Defined Under Namespace
Modules: Combineable, Transformable, Validatable Classes: OrderedCombiner, Result, ResultCombiner, UnorderedCombiner
Instance Attribute Summary collapse
-
#collection ⇒ Mongo::Collection
readonly
Collection The collection.
-
#options ⇒ Hash, BSON::Document
readonly
Options The options.
-
#requests ⇒ Array<Hash, BSON::Document>
readonly
Requests The requests.
Instance Method Summary collapse
-
#execute ⇒ Mongo::BulkWrite::Result
Execute the bulk write operation.
-
#initialize(collection, requests, options = {}) ⇒ BulkWrite
constructor
private
Create the new bulk write operation.
-
#ordered? ⇒ true, false
private
Is the bulk write ordered?.
-
#write_concern(session = nil) ⇒ WriteConcern
private
Get the write concern for the bulk write.
Constructor Details
#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.
115 116 117 118 119 |
# File 'lib/mongo/bulk_write.rb', line 115 def initialize(collection, requests, = {}) @collection = collection @requests = requests @options = || {} end |
Instance Attribute Details
#collection ⇒ Mongo::Collection (readonly)
Returns collection The collection.
29 30 31 |
# File 'lib/mongo/bulk_write.rb', line 29 def collection @collection end |
#options ⇒ Hash, BSON::Document (readonly)
Returns options The options.
35 36 37 |
# File 'lib/mongo/bulk_write.rb', line 35 def @options end |
#requests ⇒ Array<Hash, BSON::Document> (readonly)
Returns requests The requests.
32 33 34 |
# File 'lib/mongo/bulk_write.rb', line 32 def requests @requests end |
Instance Method Details
#execute ⇒ Mongo::BulkWrite::Result
Execute the bulk write operation.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mongo/bulk_write.rb', line 55 def execute operation_id = Monitoring.next_operation_id result_combiner = ResultCombiner.new operations = op_combiner.combine client.send(:with_session, @options) do |session| operations.each do |operation| if single_statement?(operation) write_concern = write_concern(session) write_with_retry(session, write_concern) do |server, txn_num| execute_operation( operation.keys.first, operation.values.flatten, server, operation_id, result_combiner, session, txn_num) end else nro_write_with_retry(session, write_concern) do |server| execute_operation( operation.keys.first, operation.values.flatten, server, operation_id, result_combiner, session) end end end end result_combiner.result end |
#ordered? ⇒ true, false
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.
Is the bulk write ordered?
131 132 133 |
# File 'lib/mongo/bulk_write.rb', line 131 def ordered? @ordered ||= .fetch(:ordered, true) end |
#write_concern(session = nil) ⇒ WriteConcern
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.
Get the write concern for the bulk write.
145 146 147 148 149 |
# File 'lib/mongo/bulk_write.rb', line 145 def write_concern(session = nil) @write_concern ||= [:write_concern] ? WriteConcern.get([:write_concern]) : collection.write_concern_with_session(session) end |