@@ -91,6 +91,14 @@ class BulkWrite implements Executable
91
91
* * upsert (boolean): When true, a new document is created if no document
92
92
* matches the query. The default is false.
93
93
*
94
+ * Supported options for replaceOne and updateOne operations:
95
+ *
96
+ * * sort (document): Determines which document the operation modifies if
97
+ * the query selects multiple documents.
98
+ *
99
+ * This is not supported for server versions < 8.0 and will result in an
100
+ * exception at execution time if used.
101
+ *
94
102
* Supported options for updateMany and updateOne operations:
95
103
*
96
104
* * arrayFilters (document array): A set of filters specifying to which
@@ -372,6 +380,10 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
372
380
throw InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][2]["collation"] ' , $ i , $ type ), $ args [2 ]['collation ' ]);
373
381
}
374
382
383
+ if (isset ($ args [2 ]['sort ' ]) && ! is_document ($ args [2 ]['sort ' ])) {
384
+ throw InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][2]["sort"] ' , $ i , $ type ), $ args [2 ]['sort ' ]);
385
+ }
386
+
375
387
if (! is_bool ($ args [2 ]['upsert ' ])) {
376
388
throw InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
377
389
}
@@ -413,6 +425,14 @@ private function validateOperations(array $operations, ?DocumentCodec $codec, En
413
425
throw InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][2]["collation"] ' , $ i , $ type ), $ args [2 ]['collation ' ]);
414
426
}
415
427
428
+ if (isset ($ args [2 ]['sort ' ]) && ! is_document ($ args [2 ]['sort ' ])) {
429
+ throw InvalidArgumentException::expectedDocumentType (sprintf ('$operations[%d]["%s"][2]["sort"] ' , $ i , $ type ), $ args [2 ]['sort ' ]);
430
+ }
431
+
432
+ if (isset ($ args [2 ]['sort ' ]) && $ args [2 ]['multi ' ]) {
433
+ throw new InvalidArgumentException (sprintf ('"sort" option cannot be used with $operations[%d]["%s"] ' , $ i , $ type ));
434
+ }
435
+
416
436
if (! is_bool ($ args [2 ]['upsert ' ])) {
417
437
throw InvalidArgumentException::invalidType (sprintf ('$operations[%d]["%s"][2]["upsert"] ' , $ i , $ type ), $ args [2 ]['upsert ' ], 'boolean ' );
418
438
}
0 commit comments