@@ -60,6 +60,8 @@ class View
6060 # to run the command when access control is enforced.
6161 # @option options [ Object ] :comment A user-provided
6262 # comment to attach to this command.
63+ # @option options [ Integer ] :timeout_ms The operation timeout in milliseconds.
64+ # Must a positive integer. The default value is unset which means infinite.
6365 #
6466 # See https://mongodb.com/docs/manual/reference/command/listCollections/
6567 # for more information and usage.
@@ -70,9 +72,14 @@ class View
7072 # @since 2.0.0
7173 def collection_names ( options = { } )
7274 @batch_size = options [ :batch_size ]
73- session = client . send ( :get_session , options )
74- cursor = read_with_retry_cursor ( session , ServerSelector . primary , self ) do |server |
75- send_initial_query ( server , session , options . merge ( name_only : true ) )
75+ session = client . get_session ( options )
76+ context = Operation ::Context . new (
77+ client : client ,
78+ session : session ,
79+ operation_timeouts : operation_timeouts ( options )
80+ )
81+ cursor = read_with_retry_cursor ( session , ServerSelector . primary , self , context : context ) do |server |
82+ send_initial_query ( server , session , context , options . merge ( name_only : true ) )
7683 end
7784 cursor . map do |info |
7885 if cursor . initial_result . connection_description . features . list_collections_enabled?
@@ -198,11 +205,16 @@ def operation_timeouts(opts = {})
198205
199206 def collections_info ( session , server_selector , options = { } , &block )
200207 description = nil
201- cursor = read_with_retry_cursor ( session , server_selector , self ) do |server |
208+ context = Operation ::Context . new (
209+ client : client ,
210+ session : session ,
211+ operation_timeouts : operation_timeouts ( options )
212+ )
213+ cursor = read_with_retry_cursor ( session , server_selector , self , context : context ) do |server |
202214 # TODO take description from the connection used to send the query
203215 # once https://jira.mongodb.org/browse/RUBY-1601 is fixed.
204216 description = server . description
205- send_initial_query ( server , session , options )
217+ send_initial_query ( server , session , context , options )
206218 end
207219 # On 3.0+ servers, we get just the collection names.
208220 # On 2.6 server, we get collection names prefixed with the database
@@ -266,15 +278,15 @@ def initial_query_op(session, options = {})
266278 # types (where possible).
267279 #
268280 # @return [ Operation::Result ] Result of the query.
269- def send_initial_query ( server , session , options = { } )
281+ def send_initial_query ( server , session , context , options = { } )
270282 opts = options . dup
271283 execution_opts = { }
272284 if opts . key? ( :deserialize_as_bson )
273285 execution_opts [ :deserialize_as_bson ] = opts . delete ( :deserialize_as_bson )
274286 end
275287 initial_query_op ( session , opts ) . execute (
276288 server ,
277- context : Operation :: Context . new ( client : client , session : session , operation_timeouts : operation_timeouts ( opts ) ) ,
289+ context : context ,
278290 options : execution_opts
279291 )
280292 end
0 commit comments