@@ -139,6 +139,7 @@ def count(opts = {})
139139 cmd [ :limit ] = opts [ :limit ] if opts [ :limit ]
140140 cmd [ :maxTimeMS ] = opts [ :max_time_ms ] if opts [ :max_time_ms ]
141141 cmd [ :readConcern ] = collection . read_concern if collection . read_concern
142+ Mongo ::Lint . validate_underscore_read_preference ( opts [ :read ] )
142143 read_pref = opts [ :read ] || read_preference
143144 selector = ServerSelector . get ( read_pref || server_selector )
144145 with_session ( opts ) do |session |
@@ -203,6 +204,7 @@ def estimated_document_count(opts = {})
203204 cmd = { count : collection . name }
204205 cmd [ :maxTimeMS ] = opts [ :max_time_ms ] if opts [ :max_time_ms ]
205206 cmd [ :readConcern ] = collection . read_concern if collection . read_concern
207+ Mongo ::Lint . validate_underscore_read_preference ( opts [ :read ] )
206208 read_pref = opts [ :read ] || read_preference
207209 selector = ServerSelector . get ( read_pref || server_selector )
208210 with_session ( opts ) do |session |
@@ -240,6 +242,7 @@ def distinct(field_name, opts = {})
240242 :query => filter }
241243 cmd [ :maxTimeMS ] = opts [ :max_time_ms ] if opts [ :max_time_ms ]
242244 cmd [ :readConcern ] = collection . read_concern if collection . read_concern
245+ Mongo ::Lint . validate_underscore_read_preference ( opts [ :read ] )
243246 read_pref = opts [ :read ] || read_preference
244247 selector = ServerSelector . get ( read_pref || server_selector )
245248 with_session ( opts ) do |session |
@@ -537,11 +540,13 @@ def collation(doc = nil)
537540 end
538541
539542 def read_preference
540- if options [ :session ] && options [ :session ] . in_transaction?
541- options [ :session ] . send ( :txn_read_pref ) || collection . client . read_preference
543+ rp = if options [ :session ] && options [ :session ] . in_transaction?
544+ options [ :session ] . txn_read_preference || collection . client . read_preference
542545 else
543546 @read_preference ||= ( options [ :read ] || collection . read_preference )
544547 end
548+ Mongo ::Lint . validate_underscore_read_preference ( rp )
549+ rp
545550 end
546551
547552 def server_selector
0 commit comments