3535from bson .raw_bson import RawBSONDocument
3636from bson .son import SON
3737from bson .timestamp import Timestamp
38- from pymongo import ASCENDING , common , helpers , message
38+ from pymongo import ASCENDING , _csot , common , helpers , message
3939from pymongo .aggregation import (
4040 _CollectionAggregationCommand ,
4141 _CollectionRawAggregationCommand ,
@@ -217,6 +217,10 @@ def __init__(
217217 self .__database : Database [_DocumentType ] = database
218218 self .__name = name
219219 self .__full_name = "%s.%s" % (self .__database .name , self .__name )
220+ self .__write_response_codec_options = self .codec_options ._replace (
221+ unicode_decode_error_handler = "replace" , document_class = dict
222+ )
223+ self ._timeout = database .client .options .timeout
220224 encrypted_fields = kwargs .pop ("encryptedFields" , None )
221225 if create or kwargs or collation :
222226 if encrypted_fields :
@@ -230,10 +234,6 @@ def __init__(
230234 else :
231235 self .__create (name , kwargs , collation , session )
232236
233- self .__write_response_codec_options = self .codec_options ._replace (
234- unicode_decode_error_handler = "replace" , document_class = dict
235- )
236-
237237 def _socket_for_reads (self , session ):
238238 return self .__database .client ._socket_for_reads (self ._read_preference_for (session ), session )
239239
@@ -433,6 +433,7 @@ def with_options(
433433 read_concern or self .read_concern ,
434434 )
435435
436+ @_csot .apply
436437 def bulk_write (
437438 self ,
438439 requests : Sequence [_WriteOp ],
@@ -631,6 +632,7 @@ def insert_one(
631632 write_concern .acknowledged ,
632633 )
633634
635+ @_csot .apply
634636 def insert_many (
635637 self ,
636638 documents : Iterable [_DocumentIn ],
@@ -1892,6 +1894,7 @@ def create_indexes(
18921894 kwargs ["comment" ] = comment
18931895 return self .__create_indexes (indexes , session , ** kwargs )
18941896
1897+ @_csot .apply
18951898 def __create_indexes (self , indexes , session , ** kwargs ):
18961899 """Internal createIndexes helper.
18971900
@@ -2088,6 +2091,7 @@ def drop_indexes(
20882091 kwargs ["comment" ] = comment
20892092 self .drop_index ("*" , session = session , ** kwargs )
20902093
2094+ @_csot .apply
20912095 def drop_index (
20922096 self ,
20932097 index_or_name : _IndexKeyHint ,
@@ -2311,6 +2315,7 @@ def options(
23112315
23122316 return options
23132317
2318+ @_csot .apply
23142319 def _aggregate (
23152320 self ,
23162321 aggregation_command ,
@@ -2618,6 +2623,7 @@ def watch(
26182623 full_document_before_change ,
26192624 )
26202625
2626+ @_csot .apply
26212627 def rename (
26222628 self ,
26232629 new_name : str ,
0 commit comments