Specific request for mongo using C # driver

I have a mongo replica set (2.0.3).

If I connect to a specific node (i.e. my connection string does not include more than one host) using the standard C # driver and specifying slaveOk (), this request will be satisfied by a random member of the set, or only ever with the node I am connected to ?

If the former, how can I achieve the latter?

Thank.

+3


source to share


3 answers


If your connection string contains only one hostname (and doesn't have replicaSet = name or connect = replicaSet), the C # driver will connect directly to that one server and only use that.

Copyset semantics (where the entire set is used) is triggered either by listing multiple node names (called a seed list), or by using replicaSet = name or connect = replicaSet.



So, if you only want to use one host, you are on the right track. You will need to specify slaveOk in the connection string, or the connection will fail if this server is not the main one.

+2


source


specifying connect = direct as a parameter in the connection string solved my problem of connecting to secondary servers via Powershell.



+1


source


Use .WithReadPreference(ReadPreference.Secondary)

for a collection provider

0


source







All Articles