Skip to content

Commit

Permalink
fix: handle read preferences without tags
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Sep 19, 2023
1 parent 9e4d569 commit 50ea98d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mongo/url_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ defmodule Mongo.UrlParser do
end
end

defp parse_tags([]) do
[]
end

defp parse_tags(tags) do
tags
|> String.split(",")
Expand Down
9 changes: 9 additions & 0 deletions test/mongo/url_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ defmodule Mongo.UrlParserTest do
]
]

assert UrlParser.parse_url(url: "mongodb://seed1.domain.com:27017,seed2.domain.com:27017/db_name?readPreference=secondary&maxStalenessSeconds=30") == [
database: "db_name",
read_preference: %{mode: :secondary, max_staleness_ms: 30_000},
seeds: [
"seed1.domain.com:27017",
"seed2.domain.com:27017"
]
]

assert UrlParser.parse_url(url: "mongodb://seed1.domain.com:27017,seed2.domain.com:27017/db_name?readPreference=weird&readPreferenceTags=dc:ny,rack:r&maxStalenessSeconds=30") == [
database: "db_name",
seeds: [
Expand Down

0 comments on commit 50ea98d

Please sign in to comment.