Authorization error when trying to change replica sets config

Hi all, hope I used the right category :sweat_smile:

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:

MongoServerError: not authorized on admin to execute command { replSetReconfig: { … }, lsid: { id: UUID(“05c1654a-0f8b-4a05-a329-ee96075b878f”) }, $clusterTime: { clusterTime: Timestamp(1687437929, 1), signature: { hash: BinData(0, 96D7D9BB520E42DBA42D75D214C2BB4B3FD670DC), keyId: 7222560349487104006 } }, $db: “admin” }

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

Any help will be appreciated :slight_smile:

The correct roles to make these changes are “clusterAdmin” and “replSetManager”.

As per my understanding, these roles are available in M20 and above.

This is an unsupported command in Atlas. If you can expand on what you are trying to achieve we may be able to provide a more appropriate answer.

Likely what you are looking for is provided by Pre-defined Replica Set Tags this does require a dedicated tier (M10+)

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

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.