@@ -156,6 +156,7 @@ def __init__(self, collection, ordered, bypass_document_validation):
156
156
self .bypass_doc_val = bypass_document_validation
157
157
self .uses_collation = False
158
158
self .uses_array_filters = False
159
+ self .uses_hint = False
159
160
self .is_retryable = True
160
161
self .retrying = False
161
162
self .started_retryable_write = False
@@ -180,7 +181,7 @@ def add_insert(self, document):
180
181
self .ops .append ((_INSERT , document ))
181
182
182
183
def add_update (self , selector , update , multi = False , upsert = False ,
183
- collation = None , array_filters = None ):
184
+ collation = None , array_filters = None , hint = None ):
184
185
"""Create an update document and add it to the list of ops.
185
186
"""
186
187
validate_ok_for_update (update )
@@ -193,13 +194,16 @@ def add_update(self, selector, update, multi=False, upsert=False,
193
194
if array_filters is not None :
194
195
self .uses_array_filters = True
195
196
cmd ['arrayFilters' ] = array_filters
197
+ if hint is not None :
198
+ self .uses_hint = True
199
+ cmd ['hint' ] = hint
196
200
if multi :
197
201
# A bulk_write containing an update_many is not retryable.
198
202
self .is_retryable = False
199
203
self .ops .append ((_UPDATE , cmd ))
200
204
201
205
def add_replace (self , selector , replacement , upsert = False ,
202
- collation = None ):
206
+ collation = None , hint = None ):
203
207
"""Create a replace document and add it to the list of ops.
204
208
"""
205
209
validate_ok_for_replace (replacement )
@@ -209,6 +213,9 @@ def add_replace(self, selector, replacement, upsert=False,
209
213
if collation is not None :
210
214
self .uses_collation = True
211
215
cmd ['collation' ] = collation
216
+ if hint is not None :
217
+ self .uses_hint = True
218
+ cmd ['hint' ] = hint
212
219
self .ops .append ((_UPDATE , cmd ))
213
220
214
221
def add_delete (self , selector , limit , collation = None ):
@@ -252,9 +259,13 @@ def gen_unordered(self):
252
259
253
260
def _execute_command (self , generator , write_concern , session ,
254
261
sock_info , op_id , retryable , full_result ):
255
- if sock_info .max_wire_version < 5 and self .uses_collation :
256
- raise ConfigurationError (
257
- 'Must be connected to MongoDB 3.4+ to use a collation.' )
262
+ if sock_info .max_wire_version < 5 :
263
+ if self .uses_collation :
264
+ raise ConfigurationError (
265
+ 'Must be connected to MongoDB 3.4+ to use a collation.' )
266
+ if self .uses_hint :
267
+ raise ConfigurationError (
268
+ 'Must be connected to MongoDB 3.4+ to use hint.' )
258
269
if sock_info .max_wire_version < 6 and self .uses_array_filters :
259
270
raise ConfigurationError (
260
271
'Must be connected to MongoDB 3.6+ to use arrayFilters.' )
@@ -428,6 +439,9 @@ def execute_no_results(self, sock_info, generator):
428
439
if self .uses_array_filters :
429
440
raise ConfigurationError (
430
441
'arrayFilters is unsupported for unacknowledged writes.' )
442
+ if self .uses_hint :
443
+ raise ConfigurationError (
444
+ 'hint is unsupported for unacknowledged writes.' )
431
445
# Cannot have both unacknowledged writes and bypass document validation.
432
446
if self .bypass_doc_val and sock_info .max_wire_version >= 4 :
433
447
raise OperationFailure ("Cannot set bypass_document_validation with"
0 commit comments