File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,8 @@ def multi_workers_ready?
173173
174174 def write ( chunk )
175175 collection_name = extract_placeholders ( @collection , chunk )
176- database_name = extract_placeholders ( @database , chunk )
176+ # In connection_string case, we shouldn't handle extract_placeholers for @database.
177+ database_name = extract_placeholders ( @database , chunk ) unless @connection_string
177178 operate ( database_name , format_collection_name ( collection_name ) , collect_records ( chunk ) )
178179 end
179180
Original file line number Diff line number Diff line change @@ -183,6 +183,27 @@ def test_write
183183 assert_equal ( expected , actual_documents )
184184 end
185185
186+ def test_write_with_connection_string
187+ d = create_driver ( %[
188+ @type mongo
189+ connection_string mongodb://localhost:#{ port } /#{ database_name }
190+ collection #{ collection_name }
191+ capped
192+ capped_size 100
193+ ] )
194+ assert_equal ( "mongodb://localhost:#{ port } /#{ database_name } " , d . instance . connection_string )
195+ assert_nil d . instance . database
196+
197+ d . run ( default_tag : 'test' ) do
198+ emit_documents ( d )
199+ end
200+ actual_documents = get_documents
201+ time = event_time ( "2011-01-02 13:14:15 UTC" )
202+ expected = [ { 'a' => 1 , d . instance . inject_config . time_key => Time . at ( time ) . localtime } ,
203+ { 'a' => 2 , d . instance . inject_config . time_key => Time . at ( time ) . localtime } ]
204+ assert_equal ( expected , actual_documents )
205+ end
206+
186207 class WriteWithCollectionPlaceholder < self
187208 def setup
188209 @tag = 'custom'
You can’t perform that action at this time.
0 commit comments