Skip to content

Commit 0c09739

Browse files
committed
PHPLIB-722: Ignore writeConcern option for read-only aggregations
1 parent 5a14dee commit 0c09739

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Operation/Aggregate.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ public function __construct(string $databaseName, ?string $collectionName, array
228228
unset($options['batchSize']);
229229
}
230230

231-
/* Ignore batchSize for writes, since no documents are returned and a
232-
* batchSize of zero could prevent the pipeline from executing. */
233231
if ($this->isWrite) {
232+
/* Ignore batchSize for writes, since no documents are returned and
233+
* a batchSize of zero could prevent the pipeline from executing. */
234234
unset($options['batchSize']);
235+
} else {
236+
unset($options['writeConcern']);
235237
}
236238

237239
$this->databaseName = $databaseName;
@@ -365,16 +367,12 @@ private function executeCommand(Server $server, Command $command): Cursor
365367
{
366368
$options = [];
367369

368-
foreach (['readConcern', 'readPreference', 'session'] as $option) {
370+
foreach (['readConcern', 'readPreference', 'session', 'writeConcern'] as $option) {
369371
if (isset($this->options[$option])) {
370372
$options[$option] = $this->options[$option];
371373
}
372374
}
373375

374-
if ($this->isWrite && isset($this->options['writeConcern'])) {
375-
$options['writeConcern'] = $this->options['writeConcern'];
376-
}
377-
378376
if (! $this->isWrite) {
379377
return $server->executeReadCommand($this->databaseName, $command, $options);
380378
}

0 commit comments

Comments
 (0)