Now, if I use .WithReadPreference(ReadPreference.Primary) , I understand that it overrides the read preference mentioned in the URI, but does it use the same tag preferences or it just tries to use default server selection algorithm?
If it is default behaviour, how can we make sure we can set readPreferenceTags for different read preferences.
Welcome back to the MongoDB forum, hope you are doing well!
As per this documentation on Tag Set List and Read Preference Modes
Tags are not compatible with mode primary, and in general, only apply when selecting a secondary member of a set for a read operation. However, the nearest read mode, when combined with a tag set list, selects the matching member with the lowest network latency. This member may be a primary or secondary.
Also, if you specify tag set lists or a maxStalenessSeconds value with primary, the driver will produce below error.
MongoInvalidArgumentError : Primary read preference cannot be combined with tags