Reputation: 9194
Probably right in front of me, but I am not sure how to set the ReadPreference.Secondary setting in the C# driver? I wanted to distribute the query load to my secondary nodes as opposed to the default. I have set slaveOk() on the nodes themselves.
Any help / example would be appreciated. I just can't find a good example of setting that property.
Thanks,
S
EDIT: So maybe ReadPreference hasn't been implemented in C# driver yet...that looks to be the case. So then I would use slaveok?
Something like one of the below?:
var mongoServer = MongoServer.Create("mongodb://localhost/?
replicaSet=myset;slaveOk=true");
var db = mongoServer.GetDatabase("MyDb");
var coll = db.GetCollection("MyColl");
or
var cs= db.CreateCollectionSettings<BsonDocument>("Users");
cs.SlaveOk = true;
var coll = db.GetCollection(cs);
EDIT2: Looks like I might need to modify connection string to decorate each Mongo Instance as well?
mongodb://serverA:27017,serverB:27017,serverC:27017/?safe=true;replicaset=myreplicaset;slaveok=true
Upvotes: 2
Views: 2228
Reputation: 12624
Yes, ReadPreferences have not been implemented in the C# driver. We at 10gen have been waiting to implement ReadPreferences until all the drivers, including mongos, could all implement at the same time. This support should come approximately at the time of server release 2.2.
Upvotes: 2