[GODRIVER-1078] Allow specifying empty value for connection URI readPreferenceTags option Created: 22/May/19  Updated: 28/Oct/23  Resolved: 04/Jun/19

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 1.0.2
Fix Version/s: 1.0.3

Type: Bug Priority: Major - P3
Reporter: Wan Bachtiar Assignee: Emmanuel Eppinger (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File ReadPrefTagsTest.go    
Issue Links:
Backports
backported by GODRIVER-1106 Backport "Allow specifying empty valu... Closed
Related

 Description   

Specifying readPreferenceTags without a value via connection string will receive an error :

panic: error parsing uri (mongodb+srv://USER:PWD@cluster-test.mongodb.net/admin?ssl=true&retryWrites=true&readPreference=secondary&readPreferenceTags=dc:ny,rack:1&readPreferenceTags=dc:ny&readPreferenceTags=): invalid value for readPreferenceTags: 

Currently the workaround is specify via option as below example:

tags := []map[string]string{map[string]string{"dc": "ny", "rack": "1" }, 
                            map[string]string{ "dc": "ny" }, 
                            map[string]string{}}
tagSets := tag.NewTagSetsFromMaps(tags)
readPrefOption := []readpref.Option{readpref.WithTagSets(tagSets...)}
readPreference, err := readpref.New(readpref.Secondary().Mode(), readPrefOption...)
if err != nil {
    panic(err)
}
opts := options.Client().ApplyURI(mongoURI).SetReadPreference(readPreference)
client, err := mongo.NewClient(opts)
if err != nil {
    panic(err)
}

Reference - list value in connection string spec : https://github.com/mongodb/specifications/blob/master/source/connection-string/connection-string-spec.rst#values



 Comments   
Comment by Githook User [ 04/Jun/19 ]

Author:

{'name': 'Emmanuel', 'email': 'manny.eppinger@mongodb.com', 'username': 'eppingere'}

Message: Fix, Test issue of readPreferenceTags= in URI

GODRIVER-1078

If URI ends with readPreferenceTags= then we just ignore that additional
tag. Tests added ensure that this additional element of the URI is
ignored

Change-Id: Ic3e1385c98156f831055da2570a8d908d95248b6
Branch: release/1.0
https://github.com/mongodb/mongo-go-driver/commit/5da02721fdef53a9009fa2470b327e64916002e7

Comment by Githook User [ 04/Jun/19 ]

Author:

{'name': 'Emmanuel', 'email': 'manny.eppinger@mongodb.com', 'username': 'eppingere'}

Message: Fix, Test issue of readPreferenceTags= in URI

GODRIVER-1078

If URI ends with readPreferenceTags= then we just ignore that additional
tag. Tests added ensure that this additional element of the URI is
ignored

Change-Id: Ic3e1385c98156f831055da2570a8d908d95248b6
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/bfd961abf162856d6dc7c6d97ec627c18e1ceed0

Comment by Emmanuel Eppinger (Inactive) [ 04/Jun/19 ]

ReadPrefTagsTest.go

Comment by Emmanuel Eppinger (Inactive) [ 04/Jun/19 ]

https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/456857

Comment by Emmanuel Eppinger (Inactive) [ 04/Jun/19 ]

https://evergreen.mongodb.com/version/5cf68d723627e0222443a39c

Comment by Ian Whalen (Inactive) [ 23/May/19 ]

We should also write a spec test for this.

Generated at Thu Feb 08 08:35:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.