@@ -134,8 +134,10 @@ def ==(other)
134134 # and *:nearest*.
135135 # - *:tag_sets* -- an array of hashes.
136136 # - *:local_threshold*.
137- # @option opts [ Session ] :session The session to use for the operation.
138- # @option opts [ Integer ] :size The size of the capped collection.
137+ # @option options [ Session ] :session The session to use for the operation.
138+ # @option options [ Integer ] :size The size of the capped collection.
139+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
140+ # Must a positive integer. The default value is unset which means infinite.
139141 # @option opts [ Hash ] :time_series Create a time-series collection.
140142 # The hash may have the following items:
141143 # - *:timeField* -- The name of the field which contains the date in each
@@ -502,6 +504,8 @@ def drop(opts = {})
502504 # @option options [ Integer ] :skip The number of docs to skip before returning results.
503505 # @option options [ Hash ] :sort The key and direction pairs by which the result set
504506 # will be sorted.
507+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
508+ # Must a positive integer. The default value is unset which means infinite.
505509 # @option options [ Hash ] :let Mapping of variables to use in the command.
506510 # See the server documentation for details.
507511 #
@@ -539,6 +543,8 @@ def find(filter = nil, options = {})
539543 # as of server version 3.6, aggregations always provide results using a
540544 # cursor and this option is therefore not valid.
541545 # @option options [ Session ] :session The session to use.
546+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
547+ # Must a positive integer. The default value is unset which means infinite.
542548 #
543549 # @return [ View::Aggregation ] The aggregation object.
544550 #
@@ -637,6 +643,8 @@ def watch(pipeline = [], options = {})
637643 # @option options [ Session ] :session The session to use.
638644 # @option options [ Object ] :comment A user-provided
639645 # comment to attach to this command.
646+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
647+ # Must a positive integer. The default value is unset which means infinite.
640648 #
641649 # @return [ Integer ] The document count.
642650 #
@@ -673,6 +681,8 @@ def count(filter = nil, options = {})
673681 # @option options [ Session ] :session The session to use.
674682 # @option options [ Object ] :comment A user-provided
675683 # comment to attach to this command.
684+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
685+ # Must a positive integer. The default value is unset which means infinite.
676686 #
677687 # @return [ Integer ] The document count.
678688 #
@@ -694,6 +704,8 @@ def count_documents(filter = {}, options = {})
694704 # @option options [ Hash ] :read The read preference options.
695705 # @option options [ Object ] :comment A user-provided
696706 # comment to attach to this command.
707+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
708+ # Must a positive integer. The default value is unset which means infinite.
697709 #
698710 # @return [ Integer ] The document count.
699711 #
@@ -715,6 +727,8 @@ def estimated_document_count(options = {})
715727 # @option options [ Hash ] :read The read preference options.
716728 # @option options [ Hash ] :collation The collation to use.
717729 # @option options [ Session ] :session The session to use.
730+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
731+ # Must a positive integer. The default value is unset which means infinite.
718732 #
719733 # @return [ Array<Object> ] The list of distinct values.
720734 #
@@ -787,6 +801,8 @@ def inspect
787801 # @option opts [ Object ] :comment A user-provided comment to attach to
788802 # this command.
789803 # @option opts [ Session ] :session The session to use for the operation.
804+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
805+ # Must a positive integer. The default value is unset which means infinite.
790806 # @option opts [ Hash ] :write_concern The write concern options.
791807 # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
792808 #
@@ -844,6 +860,8 @@ def insert_one(document, opts = {})
844860 # @option options [ true | false ] :ordered Whether the operations
845861 # should be executed in order.
846862 # @option options [ Session ] :session The session to use for the operation.
863+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
864+ # Must a positive integer. The default value is unset which means infinite.
847865 # @option options [ Hash ] :write_concern The write concern options.
848866 # Can be :w => Integer, :fsync => Boolean, :j => Boolean.
849867 #
@@ -872,6 +890,8 @@ def insert_many(documents, options = {})
872890 # @option options [ true | false ] :bypass_document_validation Whether or
873891 # not to skip document level validation.
874892 # @option options [ Session ] :session The session to use for the set of operations.
893+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
894+ # Must a positive integer. The default value is unset which means infinite.
875895 # @option options [ Hash ] :let Mapping of variables to use in the command.
876896 # See the server documentation for details.
877897 #
@@ -894,6 +914,8 @@ def bulk_write(requests, options = {})
894914 # @option options [ Session ] :session The session to use.
895915 # @option options [ Hash | String ] :hint The index to use for this operation.
896916 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
917+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
918+ # Must a positive integer. The default value is unset which means infinite.
897919 # @option options [ Hash ] :let Mapping of variables to use in the command.
898920 # See the server documentation for details.
899921 #
@@ -916,6 +938,8 @@ def delete_one(filter = nil, options = {})
916938 # @option options [ Session ] :session The session to use.
917939 # @option options [ Hash | String ] :hint The index to use for this operation.
918940 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
941+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
942+ # Must a positive integer. The default value is unset which means infinite.
919943 # @option options [ Hash ] :let Mapping of variables to use in the command.
920944 # See the server documentation for details.
921945 #
@@ -964,6 +988,8 @@ def parallel_scan(cursor_count, options = {})
964988 # not to skip document level validation.
965989 # @option options [ Hash ] :collation The collation to use.
966990 # @option options [ Session ] :session The session to use.
991+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
992+ # Must a positive integer. The default value is unset which means infinite.
967993 # @option options [ Hash | String ] :hint The index to use for this operation.
968994 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
969995 # @option options [ Hash ] :let Mapping of variables to use in the command.
@@ -993,6 +1019,8 @@ def replace_one(filter, replacement, options = {})
9931019 # @option options [ Array ] :array_filters A set of filters specifying to which array elements
9941020 # an update should apply.
9951021 # @option options [ Session ] :session The session to use.
1022+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
1023+ # Must a positive integer. The default value is unset which means infinite.
9961024 # @option options [ Hash | String ] :hint The index to use for this operation.
9971025 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
9981026 # @option options [ Hash ] :let Mapping of variables to use in the command.
@@ -1022,6 +1050,8 @@ def update_many(filter, update, options = {})
10221050 # @option options [ Array ] :array_filters A set of filters specifying to which array elements
10231051 # an update should apply.
10241052 # @option options [ Session ] :session The session to use.
1053+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
1054+ # Must a positive integer. The default value is unset which means infinite.
10251055 # @option options [ Hash | String ] :hint The index to use for this operation.
10261056 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
10271057 # @option options [ Hash ] :let Mapping of variables to use in the command.
@@ -1052,6 +1082,8 @@ def update_one(filter, update, options = {})
10521082 # Defaults to the collection's write concern.
10531083 # @option options [ Hash ] :collation The collation to use.
10541084 # @option options [ Session ] :session The session to use.
1085+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
1086+ # Must a positive integer. The default value is unset which means infinite.
10551087 # @option options [ Hash | String ] :hint The index to use for this operation.
10561088 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
10571089 # @option options [ Hash ] :let Mapping of variables to use in the command.
@@ -1096,6 +1128,8 @@ def find_one_and_delete(filter, options = {})
10961128 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
10971129 # @option options [ Hash ] :let Mapping of variables to use in the command.
10981130 # See the server documentation for details.
1131+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
1132+ # Must a positive integer. The default value is unset which means infinite.
10991133 #
11001134 # @return [ BSON::Document ] The document.
11011135 #
@@ -1132,6 +1166,8 @@ def find_one_and_update(filter, update, options = {})
11321166 # @option options [ Session ] :session The session to use.
11331167 # @option options [ Hash | String ] :hint The index to use for this operation.
11341168 # May be specified as a Hash (e.g. { _id: 1 }) or a String (e.g. "_id_").
1169+ # @option options [ Integer ] :timeout_ms The per-operation timeout in milliseconds.
1170+ # Must a positive integer. The default value is unset which means infinite.
11351171 # @option options [ Hash ] :let Mapping of variables to use in the command.
11361172 # See the server documentation for details.
11371173 #
@@ -1164,10 +1200,10 @@ def system_collection?
11641200 end
11651201
11661202 def timeout_ms ( opts = { } )
1167- if opts . key? ( :timeout_ms )
1168- opts . delete ( :timeout_ms )
1203+ if opts [ :timeout_ms ] . nil?
1204+ options [ :timeout_ms ] || database . timeout_ms
11691205 else
1170- options . fetch ( :timeout_ms ) { database . timeout_ms }
1206+ opts . delete ( :timeout_ms )
11711207 end
11721208 end
11731209 end
0 commit comments