简体   繁体   English

如何使用C#驱动程序针对mongo设置单个查询的readPreference

[英]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.

相关问题 如何使用mongo db c#驱动程序执行“和”查询? - How to do “And” queries using mongo db c# driver? 使用C#mongo驱动程序执行复杂的mongo JSON查询 - Execute complex mongo JSON query using C# mongo driver 如何使用官方 c# 驱动程序使用 MongoDB 中的 Update.Set 更新多个字段? - How do you update multiple field using Update.Set in MongoDB using official c# driver? 在Mongo Server 4.0上的C#驱动程序2.7.0中如何执行db.collection.explain()? - How do you perform db.collection.explain() in C# driver 2.7.0 on Mongo Server 4.0? 如何在c#驱动程序中为mongo集合中的所有文本字段创建全文搜索? - How do you create a full text search for all text fields in a mongo collection in the c# driver? 如何使用 Mongo.Driver.Linq 和 Mongo C# 驱动程序 2.3 返回带有过滤子文档的文档? - How do I return a document with filtered sub-documents using Mongo.Driver.Linq with the Mongo C# driver 2.3? 如何通过一次调用使用mongo db C#驱动程序添加嵌套元素或更新属性 - How can you add a nested element or update a property using mongo db C# driver with one call 如何使用 C# 驱动程序以编程方式在 MongoDB 查询上设置排序字段? - How do I programmatically set the sort field on a MongoDB query using the C# driver? C# Mongo 驱动程序:使用连接和 UpdateManyAsync 更新查询 - C# Mongo driver: Update query using joins and UpdateManyAsync 如何使用2.4 C#Mongo驱动程序运行解释查询? - How do I run an explain query with the 2.4 C# Mongo driver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM