Skip to content

Commit d92d3a9

Browse files
committed
Append readConcern to explain command documents only
1 parent 987beda commit d92d3a9

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

src/Operation/Aggregate.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ public function execute(Server $server)
309309
*/
310310
public function getCommandDocument(Server $server)
311311
{
312-
return $this->createCommandDocument();
312+
$cmd = $this->createCommandDocument();
313+
314+
// Read concern can change the query plan
315+
if (isset($this->options['readConcern'])) {
316+
$cmd['readConcern'] = $this->options['readConcern'];
317+
}
318+
319+
return $cmd;
313320
}
314321

315322
/**
@@ -322,7 +329,7 @@ private function createCommandDocument(): array
322329
'pipeline' => $this->pipeline,
323330
];
324331

325-
foreach (['allowDiskUse', 'bypassDocumentValidation', 'comment', 'explain', 'maxTimeMS', 'readConcern'] as $option) {
332+
foreach (['allowDiskUse', 'bypassDocumentValidation', 'comment', 'explain', 'maxTimeMS'] as $option) {
326333
if (isset($this->options[$option])) {
327334
$cmd[$option] = $this->options[$option];
328335
}

src/Operation/Count.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ public function execute(Server $server)
173173
*/
174174
public function getCommandDocument(Server $server)
175175
{
176-
return $this->createCommandDocument();
176+
$cmd = $this->createCommandDocument();
177+
178+
// Read concern can change the query plan
179+
if (isset($this->options['readConcern'])) {
180+
$cmd['readConcern'] = $this->options['readConcern'];
181+
}
182+
183+
return $cmd;
177184
}
178185

179186
/**

src/Operation/Distinct.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ public function execute(Server $server)
166166
*/
167167
public function getCommandDocument(Server $server)
168168
{
169-
return $this->createCommandDocument();
169+
$cmd = $this->createCommandDocument();
170+
171+
// Read concern can change the query plan
172+
if (isset($this->options['readConcern'])) {
173+
$cmd['readConcern'] = $this->options['readConcern'];
174+
}
175+
176+
return $cmd;
170177
}
171178

172179
/**
@@ -187,7 +194,7 @@ private function createCommandDocument(): array
187194
$cmd['collation'] = (object) $this->options['collation'];
188195
}
189196

190-
foreach (['comment', 'maxTimeMS', 'readConcern'] as $option) {
197+
foreach (['comment', 'maxTimeMS'] as $option) {
191198
if (isset($this->options[$option])) {
192199
$cmd[$option] = $this->options[$option];
193200
}

src/Operation/Find.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,14 @@ public function execute(Server $server)
330330
*/
331331
public function getCommandDocument(Server $server)
332332
{
333-
return $this->createCommandDocument();
333+
$cmd = $this->createCommandDocument();
334+
335+
// Read concern can change the query plan
336+
if (isset($this->options['readConcern'])) {
337+
$cmd['readConcern'] = $this->options['readConcern'];
338+
}
339+
340+
return $cmd;
334341
}
335342

336343
/**
@@ -349,9 +356,6 @@ private function createCommandDocument(): array
349356
// maxAwaitTimeMS is a Query level option so should not be considered here
350357
unset($options['maxAwaitTimeMS']);
351358

352-
// writeConcern is not relevant to evaluating the query plan
353-
unset($options['writeConcern']);
354-
355359
$modifierFallback = [
356360
['allowPartialResults', 'partial'],
357361
['comment', '$comment'],

src/Operation/FindAndModify.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,14 @@ public function execute(Server $server)
264264
*/
265265
public function getCommandDocument(Server $server)
266266
{
267-
return $this->createCommandDocument();
267+
$cmd = $this->createCommandDocument();
268+
269+
// Read concern can change the query plan
270+
if (isset($this->options['readConcern'])) {
271+
$cmd['readConcern'] = $this->options['readConcern'];
272+
}
273+
274+
return $cmd;
268275
}
269276

270277
/**

src/Operation/Update.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,6 @@ public function getCommandDocument(Server $server)
228228
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
229229
}
230230

231-
if (isset($this->options['writeConcern'])) {
232-
$cmd['writeConcern'] = $this->options['writeConcern'];
233-
}
234-
235231
return $cmd;
236232
}
237233

0 commit comments

Comments
 (0)