I’m trying to add tags to my cluster’s replica sets in order to customize the read preference
I followed this guide: Configure Replica Set Tag Sets — MongoDB Manual
I can get the config using the rs.conf() command (initially I had an issue with this as well because my user wasn’t an admin)
But then after changing the tags it fails when trying to run rs.reconfig(conf) to save the new config
If I try to run this command from my windows terminal I just get this error over and over:
Reconfig did not succeed yet, starting new attempt…
If I try the same from the shell in the Compass app I get the actual authorization error:
I tried playing around with the user roles and tried assigning any role that seemed relevant, but it didn’t help. These are the roles currently defined on the user:
Also probably relevant to mention that I’m using the M10 cluster tier
I want to be able to spread my read requests across the 3 replicas I have (primary + 2 secondaries) using a customized read perference
Because by using the PrimaryPreferred preference it only uses the primary and never gets to the secondaries, and by using SecondaryPreferred it never uses the primary
My idea in general was to assign a number for each replica (0-2), and from my code rotate which tag is preferred for each call - first read prefer #0, second read prefer #1, etc. (the actual logic may be a little more complex and will actually prefer secondaries over the primary, but that’s the general idea)
The pre-defined tags don’t help me because they are exactly the same for all the replicas, so I need to be able to add a custom tag on each replica
For anyone interested - I was able to accomplish what I need by randomizing the read preference between PrimaryPreferred and SecondaryPreferred when I make calls, I gave the secondaries a 67% chance of being chosen and so I got a pretty even distirbution of the queries across the replicas