From 50ea98db82217bbd9a2f37ad57f6f271b2bff7c2 Mon Sep 17 00:00:00 2001 From: zookzook Date: Tue, 19 Sep 2023 16:16:30 +0200 Subject: [PATCH] fix: handle read preferences without tags --- lib/mongo/url_parser.ex | 4 ++++ test/mongo/url_parser_test.exs | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/mongo/url_parser.ex b/lib/mongo/url_parser.ex index 5fa8050c..736070b1 100644 --- a/lib/mongo/url_parser.ex +++ b/lib/mongo/url_parser.ex @@ -236,6 +236,10 @@ defmodule Mongo.UrlParser do end end + defp parse_tags([]) do + [] + end + defp parse_tags(tags) do tags |> String.split(",") diff --git a/test/mongo/url_parser_test.exs b/test/mongo/url_parser_test.exs index c65b52b5..09a9c51a 100644 --- a/test/mongo/url_parser_test.exs +++ b/test/mongo/url_parser_test.exs @@ -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: [