Skip to content

Commit c85fd1b

Browse files
authored
Merge pull request #117 from fluent/dont-handle-database-placeholders-when-connection_string-specified
Don't handle database placholders when specifying connection_string parameter
2 parents ee62344 + a4757d1 commit c85fd1b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/fluent/plugin/out_mongo.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

test/plugin/test_out_mongo.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

0 commit comments

Comments
 (0)