35
35
InvalidOperation ,
36
36
OperationFailure )
37
37
from pymongo .message import (_INSERT , _UPDATE , _DELETE ,
38
- _do_batched_insert ,
39
38
_randint ,
40
39
_BulkWriteContext ,
41
40
_EncryptedBulkWriteContext )
@@ -256,17 +255,6 @@ def gen_unordered(self):
256
255
257
256
def _execute_command (self , generator , write_concern , session ,
258
257
sock_info , op_id , retryable , full_result ):
259
- if sock_info .max_wire_version < 5 :
260
- if self .uses_collation :
261
- raise ConfigurationError (
262
- 'Must be connected to MongoDB 3.4+ to use a collation.' )
263
- if self .uses_hint :
264
- raise ConfigurationError (
265
- 'Must be connected to MongoDB 3.4+ to use hint.' )
266
- if sock_info .max_wire_version < 6 and self .uses_array_filters :
267
- raise ConfigurationError (
268
- 'Must be connected to MongoDB 3.6+ to use arrayFilters.' )
269
-
270
258
db_name = self .collection .database .name
271
259
client = self .collection .database .client
272
260
listeners = client ._event_listeners
@@ -283,7 +271,7 @@ def _execute_command(self, generator, write_concern, session,
283
271
('ordered' , self .ordered )])
284
272
if not write_concern .is_server_default :
285
273
cmd ['writeConcern' ] = write_concern .document
286
- if self .bypass_doc_val and sock_info . max_wire_version >= 4 :
274
+ if self .bypass_doc_val :
287
275
cmd ['bypassDocumentValidation' ] = True
288
276
bwc = self .bulk_ctx_class (
289
277
db_name , cmd , sock_info , op_id , listeners , session ,
@@ -358,24 +346,6 @@ def retryable_bulk(session, sock_info, retryable):
358
346
_raise_bulk_write_error (full_result )
359
347
return full_result
360
348
361
- def execute_insert_no_results (self , sock_info , run , op_id , acknowledged ):
362
- """Execute insert, returning no results.
363
- """
364
- command = SON ([('insert' , self .collection .name ),
365
- ('ordered' , self .ordered )])
366
- concern = {'w' : int (self .ordered )}
367
- command ['writeConcern' ] = concern
368
- if self .bypass_doc_val and sock_info .max_wire_version >= 4 :
369
- command ['bypassDocumentValidation' ] = True
370
- db = self .collection .database
371
- bwc = _BulkWriteContext (
372
- db .name , command , sock_info , op_id , db .client ._event_listeners ,
373
- None , _INSERT , self .collection .codec_options )
374
- # Legacy batched OP_INSERT.
375
- _do_batched_insert (
376
- self .collection .full_name , run .ops , True , acknowledged , concern ,
377
- not self .ordered , self .collection .codec_options , bwc )
378
-
379
349
def execute_op_msg_no_results (self , sock_info , generator ):
380
350
"""Execute write commands with OP_MSG and w=0 writeConcern, unordered.
381
351
"""
@@ -441,62 +411,13 @@ def execute_no_results(self, sock_info, generator):
441
411
raise ConfigurationError (
442
412
'hint is unsupported for unacknowledged writes.' )
443
413
# Cannot have both unacknowledged writes and bypass document validation.
444
- if self .bypass_doc_val and sock_info . max_wire_version >= 4 :
414
+ if self .bypass_doc_val :
445
415
raise OperationFailure ("Cannot set bypass_document_validation with"
446
416
" unacknowledged write concern" )
447
417
448
- # OP_MSG
449
- if sock_info .max_wire_version > 5 :
450
- if self .ordered :
451
- return self .execute_command_no_results (sock_info , generator )
452
- return self .execute_op_msg_no_results (sock_info , generator )
453
-
454
- coll = self .collection
455
- # If ordered is True we have to send GLE or use write
456
- # commands so we can abort on the first error.
457
- write_concern = WriteConcern (w = int (self .ordered ))
458
- op_id = _randint ()
459
-
460
- next_run = next (generator )
461
- while next_run :
462
- # An ordered bulk write needs to send acknowledged writes to short
463
- # circuit the next run. However, the final message on the final
464
- # run can be unacknowledged.
465
- run = next_run
466
- next_run = next (generator , None )
467
- needs_ack = self .ordered and next_run is not None
468
- try :
469
- if run .op_type == _INSERT :
470
- self .execute_insert_no_results (
471
- sock_info , run , op_id , needs_ack )
472
- elif run .op_type == _UPDATE :
473
- for operation in run .ops :
474
- doc = operation ['u' ]
475
- check_keys = True
476
- if doc and next (iter (doc )).startswith ('$' ):
477
- check_keys = False
478
- coll ._update (
479
- sock_info ,
480
- operation ['q' ],
481
- doc ,
482
- upsert = operation ['upsert' ],
483
- check_keys = check_keys ,
484
- multi = operation ['multi' ],
485
- write_concern = write_concern ,
486
- op_id = op_id ,
487
- ordered = self .ordered ,
488
- bypass_doc_val = self .bypass_doc_val )
489
- else :
490
- for operation in run .ops :
491
- coll ._delete (sock_info ,
492
- operation ['q' ],
493
- not operation ['limit' ],
494
- write_concern ,
495
- op_id ,
496
- self .ordered )
497
- except OperationFailure :
498
- if self .ordered :
499
- break
418
+ if self .ordered :
419
+ return self .execute_command_no_results (sock_info , generator )
420
+ return self .execute_op_msg_no_results (sock_info , generator )
500
421
501
422
def execute (self , write_concern , session ):
502
423
"""Execute operations.
0 commit comments