I’m encountering an unexpected behavior with MongoDB’s read preference tags where read operations are being served from replica set members that do not match the specified tag sets or no any tags present.
Here are the details:
Environment:
MongoDB version: 6.0.1
Deployment type: Replica set
Number of replica set members: 3
Deployment configuration: replica set
Use Case:
I am attempting to utilize a dedicated replica for a specific operation while also implementing a fallback mechanism.
The desired behavior is as follows:
Specify read preference tags to route a specific operation to a dedicated replica.
If the dedicated replica is unavailable, fallback to any available node from the common replicas.
Steps to Reproduce:
Configure a MongoDB replica set with multiple members.
Specify read preference tags in the MongoDB URI, for example:
URI = mongodb://test_db:read_db!2017@server_1:27017,server_2:27017,server_3:27017/db?replicaSet=re_test_db_set&readPreference=secondaryPreferred&readPreferenceTags=use:dedicatedReplica
Perform read operations against the replica set.
Expected Behavior:
I expect MongoDB to strictly enforce the specified read preference tags and only serve read operations from replica set members that match the specified tag sets. If no members match the criteria, I expect MongoDB to return an error indicating that no suitable members were found.
Actual Behavior:
Despite specifying read preference tags in the URI, MongoDB returns data even if no replica set members match the specified tag sets. It appears that MongoDB is prioritizing performance and availability over strict adherence to read preference tags.
Questions:
Is this behavior expected or documented behavior in MongoDB?
Is there a way to enforce strict adherence to read preference tags, such that MongoDB returns an error if no suitable members are found?
Are there any best practices or recommendations for ensuring that read preference tags are enforced strictly in a replica set deployment?
Conclusion:
I would appreciate any insights, recommendations, or guidance on how to address this issue and ensure that MongoDB strictly enforces read preference tags according to the specified criteria.
Thank you for your assistance!