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