Set slaveOK with MongoDB.Driver

Hi there,

My C# code uses MongoDB.Driver latest version and I’m trying to get data from a mongodb secondary server.
I wonder how can I set SetSlaveOK() in my C# code or maybe run a rs.slaveOk() command before querying.
Tested with Robo 3T and it works just fine if i run rs.slaveOk() before any other command.
I have no mongodb client on any machine. Just credentials to connect to this secondary server.
Can you guide me how to solve it?

Thank you,
Radu.

Hi @Radu_Pozneac

This is also known as read preference. If you use a mongo uri you can append the option readPreference=secondary or readPreference-secondaryPreferred.

Same thing can be set directly with MongoClientSettings.ReadPreference Property

2 Likes

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