@@ -295,6 +295,36 @@ function (array $event) {
295
295
);
296
296
}
297
297
298
+ public function testBulkWriteWithPipelineUpdates ()
299
+ {
300
+ if (version_compare ($ this ->getServerVersion (), '4.2.0 ' , '< ' )) {
301
+ $ this ->markTestSkipped ('Pipeline-style updates are not supported ' );
302
+ }
303
+
304
+ $ this ->createFixtures (4 );
305
+
306
+ $ ops = [
307
+ ['updateOne ' => [['_id ' => 2 ], [['$addFields ' => ['y ' => 2 ]]]]],
308
+ ['updateMany ' => [['_id ' => ['$gt ' => 2 ]], [['$addFields ' => ['y ' => '$_id ' ]]]]],
309
+ ];
310
+
311
+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
312
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
313
+
314
+ $ this ->assertInstanceOf (BulkWriteResult::class, $ result );
315
+ $ this ->assertSame (3 , $ result ->getMatchedCount ());
316
+ $ this ->assertSame (3 , $ result ->getModifiedCount ());
317
+
318
+ $ expected = [
319
+ ['_id ' => 1 , 'x ' => 11 ],
320
+ ['_id ' => 2 , 'x ' => 22 , 'y ' => 2 ],
321
+ ['_id ' => 3 , 'x ' => 33 , 'y ' => 3 ],
322
+ ['_id ' => 4 , 'x ' => 44 , 'y ' => 4 ],
323
+ ];
324
+
325
+ $ this ->assertSameDocuments ($ expected , $ this ->collection ->find ());
326
+ }
327
+
298
328
/**
299
329
* Create data fixtures.
300
330
*
0 commit comments