@@ -176,7 +176,8 @@ impl TopologyDescription {
176
176
) {
177
177
match ( self . topology_type , server_type) {
178
178
( TopologyType :: Sharded , ServerType :: Mongos )
179
- | ( TopologyType :: Single , ServerType :: Mongos ) => {
179
+ | ( TopologyType :: Single , ServerType :: Mongos )
180
+ | ( TopologyType :: LoadBalanced , _) => {
180
181
self . update_command_read_pref_for_mongos ( command, criteria)
181
182
}
182
183
( TopologyType :: Single , ServerType :: Standalone ) => { }
@@ -212,27 +213,20 @@ impl TopologyDescription {
212
213
command : & mut Command < T > ,
213
214
criteria : Option < & SelectionCriteria > ,
214
215
) {
215
- match criteria {
216
- Some ( SelectionCriteria :: ReadPreference ( ReadPreference :: Secondary { ref options } ) ) => {
217
- command. set_read_preference ( ReadPreference :: Secondary {
218
- options : options. clone ( ) ,
219
- } )
216
+ let read_preference = match criteria {
217
+ Some ( SelectionCriteria :: ReadPreference ( rp) ) => rp,
218
+ _ => return ,
219
+ } ;
220
+ match read_preference {
221
+ ReadPreference :: Secondary { .. }
222
+ | ReadPreference :: PrimaryPreferred { .. }
223
+ | ReadPreference :: Nearest { .. } => {
224
+ command. set_read_preference ( read_preference. clone ( ) )
220
225
}
221
- Some ( SelectionCriteria :: ReadPreference ( ReadPreference :: PrimaryPreferred {
222
- ref options,
223
- } ) ) => command. set_read_preference ( ReadPreference :: PrimaryPreferred {
224
- options : options. clone ( ) ,
225
- } ) ,
226
- Some ( SelectionCriteria :: ReadPreference ( ReadPreference :: SecondaryPreferred {
227
- ref options,
228
- } ) ) if options. max_staleness . is_some ( ) || options. tag_sets . is_some ( ) => command
229
- . set_read_preference ( ReadPreference :: SecondaryPreferred {
230
- options : options. clone ( ) ,
231
- } ) ,
232
- Some ( SelectionCriteria :: ReadPreference ( ReadPreference :: Nearest { ref options } ) ) => {
233
- command. set_read_preference ( ReadPreference :: Nearest {
234
- options : options. clone ( ) ,
235
- } )
226
+ ReadPreference :: SecondaryPreferred { ref options }
227
+ if options. max_staleness . is_some ( ) || options. tag_sets . is_some ( ) =>
228
+ {
229
+ command. set_read_preference ( read_preference. clone ( ) )
236
230
}
237
231
_ => { }
238
232
}
0 commit comments