@@ -16,6 +16,7 @@ import (
16
16
"go.mongodb.org/mongo-driver/mongo/readconcern"
17
17
"go.mongodb.org/mongo-driver/mongo/readpref"
18
18
"go.mongodb.org/mongo-driver/mongo/writeconcern"
19
+ "go.mongodb.org/mongo-driver/tag"
19
20
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
20
21
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
21
22
"go.mongodb.org/mongo-driver/x/mongo/driver/uuid"
@@ -397,6 +398,25 @@ func TestOperation(t *testing.T) {
397
398
readpref .SecondaryPreferred (readpref .WithTags ("disk" , "ssd" , "use" , "reporting" )),
398
399
description .RSSecondary , description .ReplicaSet , false , rpWithTags ,
399
400
},
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
+ },
400
420
{
401
421
"secondaryPreferred/withMaxStaleness" ,
402
422
readpref .SecondaryPreferred (readpref .WithMaxStaleness (25 * time .Second )),
0 commit comments