diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index decd0e6147..d66114fad0 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -873,7 +873,12 @@ func MergeClientOptions(opts ...*ClientOptions) *ClientOptions { if opt.err != nil { c.err = opt.err } - + if opt.uri != "" { + c.uri = opt.uri + } + if opt.cs != nil { + c.cs = opt.cs + } } return c diff --git a/mongo/options/clientoptions_test.go b/mongo/options/clientoptions_test.go index 819e046612..2a69fcfc1d 100644 --- a/mongo/options/clientoptions_test.go +++ b/mongo/options/clientoptions_test.go @@ -175,6 +175,16 @@ func TestClientOptions(t *testing.T) { t.Errorf("Merged client options do not match. got %v; want %v", got.err.Error(), opt1.err.Error()) } }) + + t.Run("MergeClientOptions/uri", func(t *testing.T) { + opt1, opt2 := Client(), Client() + opt1.uri = "Test URI" + + got := MergeClientOptions(nil, opt1, opt2) + if got.uri != "Test URI" { + t.Errorf("Merged client options do not match. got %v; want %v", got.uri, opt1.uri) + } + }) }) t.Run("ApplyURI", func(t *testing.T) { baseClient := func() *ClientOptions {