[英]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. 我有一个应用程序使用了许多不同的mongo数据库,并且有99%的时间需要从副本集的主数据库中读取数据,但是我有几个报告查询会拉回大量数据,并且不包含在索引中,我希望他们与中学竞争。 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(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.