@@ -85,8 +85,6 @@ class Collection
8585 'root ' => BSONDocument::class,
8686 ];
8787
88- private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8 ;
89-
9088 /** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
9189 private readonly Encoder $ builderEncoder ;
9290
@@ -227,24 +225,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
227225 $ hasWriteStage = is_last_pipeline_operator_write ($ pipeline );
228226
229227 $ options = $ this ->inheritReadPreference ($ options );
230-
231- $ server = $ hasWriteStage
232- ? select_server_for_aggregate_write_stage ($ this ->manager , $ options )
233- : select_server ($ this ->manager , $ options );
234-
235- /* MongoDB 4.2 and later supports a read concern when an $out stage is
236- * being used, but earlier versions do not.
237- */
238- if (! $ hasWriteStage || server_supports_feature ($ server , self ::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE )) {
239- $ options = $ this ->inheritReadConcern ($ options );
240- }
241-
228+ $ options = $ this ->inheritReadConcern ($ options );
242229 $ options = $ this ->inheritCodecOrTypeMap ($ options );
243230
244231 if ($ hasWriteStage ) {
245232 $ options = $ this ->inheritWriteOptions ($ options );
246233 }
247234
235+ $ server = $ hasWriteStage
236+ ? select_server_for_aggregate_write_stage ($ this ->manager , $ options )
237+ : select_server ($ this ->manager , $ options );
238+
248239 $ operation = new Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options );
249240
250241 return $ operation ->execute ($ server );
0 commit comments