@@ -16,6 +16,7 @@ import (
1616 "go.mongodb.org/mongo-driver/mongo/readconcern"
1717 "go.mongodb.org/mongo-driver/mongo/readpref"
1818 "go.mongodb.org/mongo-driver/mongo/writeconcern"
19+ "go.mongodb.org/mongo-driver/tag"
1920 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
2021 "go.mongodb.org/mongo-driver/x/mongo/driver/session"
2122 "go.mongodb.org/mongo-driver/x/mongo/driver/uuid"
@@ -397,6 +398,25 @@ func TestOperation(t *testing.T) {
397398 readpref .SecondaryPreferred (readpref .WithTags ("disk" , "ssd" , "use" , "reporting" )),
398399 description .RSSecondary , description .ReplicaSet , false , rpWithTags ,
399400 },
401+ // GODRIVER-2205: Ensure empty tag sets are written as an empty document in the read
402+ // preference document. Empty tag sets match any server and are used as a fallback when
403+ // no other tag sets match any servers.
404+ {
405+ "secondaryPreferred/withTags/emptyTagSet" ,
406+ readpref .SecondaryPreferred (readpref .WithTagSets (
407+ tag.Set {{Name : "disk" , Value : "ssd" }},
408+ tag.Set {})),
409+ description .RSSecondary ,
410+ description .ReplicaSet ,
411+ false ,
412+ bsoncore .NewDocumentBuilder ().
413+ AppendString ("mode" , "secondaryPreferred" ).
414+ AppendArray ("tags" , bsoncore .NewArrayBuilder ().
415+ AppendDocument (bsoncore .NewDocumentBuilder ().AppendString ("disk" , "ssd" ).Build ()).
416+ AppendDocument (bsoncore .NewDocumentBuilder ().Build ()).
417+ Build ()).
418+ Build (),
419+ },
400420 {
401421 "secondaryPreferred/withMaxStaleness" ,
402422 readpref .SecondaryPreferred (readpref .WithMaxStaleness (25 * time .Second )),
0 commit comments