简体   繁体   中英

How do you set the readPreference for a single query against mongo using the c# driver

I have an application using a number of different mongo databases and 99% of the time it needs to read from the primary of the replica set but I have a couple reporting queries that pull back a lot of data and are not covered by indexes and I would like them to run against a secondary. Is there any way to specify for a single query that it should have a read preference of secondary. I am wanting to avoid having more connection strings as I already have near a dozen in the application.

为此,集合中有几个WithXXX方法。

collection.WithReadPreference(ReadPreference.SecondaryPreferred).Find(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM