Skip to content

Commit b8871ab

Browse files
committed
RUBY-1028: Improve performance of OP_INSERT upconversion
1 parent b32acec commit b8871ab

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

lib/mongo/protocol/insert.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ def op_code
104104
# @since 2.1.0
105105
class Upconverter
106106

107+
# Insert field constant.
108+
#
109+
# @since 2.1.0
110+
INSERT = 'insert'.freeze
111+
112+
# Documents field constant.
113+
#
114+
# @since 2.1.0
115+
DOCUMENTS = 'documents'.freeze
116+
117+
# Ordered field constant.
118+
#
119+
# @since 2.1.0
120+
ORDERED = 'ordered'.freeze
121+
122+
# Write concern field constant.
123+
#
124+
# @since 2.1.0
125+
WRITE_CONCERN = 'writeConcern'.freeze
126+
107127
# @return [ String ] collection The name of the collection.
108128
attr_reader :collection
109129

@@ -138,12 +158,11 @@ def initialize(collection, documents, options)
138158
#
139159
# @since 2.1.0
140160
def command
141-
document = BSON::Document.new(
142-
insert: collection,
143-
documents: documents,
144-
ordered: options.fetch(:ordered, true)
145-
)
146-
document.merge!(writeConcern: options[:write_concern].options) if options[:write_concern]
161+
document = BSON::Document.new
162+
document.store(INSERT, collection)
163+
document.store(DOCUMENTS, documents)
164+
document.store(ORDERED, options.fetch(:ordered, true))
165+
document.merge!(WRITE_CONCERN => options[:write_concern].options) if options[:write_concern]
147166
document
148167
end
149168
end

0 commit comments

Comments
 (0)