Skip to content

Commit 5ec4848

Browse files
committed
Use aggregate with $out in executeReadWriteCommand tests
MongoDB 4.0.x (and possibly earlier) happens to require an $out stage for aggregate if a writeConcern option would be used. While this test doesn't use a write concern, it could inherit one from MONGODB_URI. As for findAndModify, that is only considered a write command (does not accept a readConcern option).
1 parent b8bd32f commit 5ec4848

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tests/manager/manager-executeReadWriteCommand-001.phpt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@ MongoDB\Driver\Manager::executeReadWriteCommand()
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_live(); ?>
66
<?php skip_if_not_clean(); ?>
7-
<?php skip_if_server_version('<', '3.2'); ?>
7+
<?php skip_if_server_version('<', '3.4'); /* aggregate write concern */ ?>
88
--FILE--
99
<?php
1010
require_once __DIR__ . "/../utils/basic.inc";
1111
require_once __DIR__ . "/../utils/observer.php";
1212

1313
$manager = new MongoDB\Driver\Manager(URI);
1414

15+
$command = new MongoDB\Driver\Command([
16+
'aggregate' => COLLECTION_NAME,
17+
'pipeline' => [
18+
['$group' => ['_id' => 1]],
19+
['$out' => COLLECTION_NAME . '.out'],
20+
],
21+
'cursor' => (object) [],
22+
]);
23+
1524
(new CommandObserver)->observe(
16-
function() use ($manager) {
17-
$command = new MongoDB\Driver\Command( [
18-
'findAndModify' => NS,
19-
'update' => [ '$set' => [ 'foo' => 'bar' ] ],
20-
] );
25+
function() use ($manager, $command) {
2126
$manager->executeReadWriteCommand(
2227
DATABASE_NAME,
2328
$command,

tests/manager/manager-executeReadWriteCommand-002.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ var_dump($session->getServer() instanceof \MongoDB\Driver\Server);
2626

2727
$command = new MongoDB\Driver\Command([
2828
'aggregate' => COLLECTION_NAME,
29-
'pipeline' => [['$group' => ['_id' => 1]]],
29+
'pipeline' => [
30+
['$group' => ['_id' => 1]],
31+
/* Note: $out cannot be used in a transaction. This is technically not a
32+
* write command, but it works for the purposes of this test. */
33+
],
3034
'cursor' => (object) []
3135
]);
3236
$manager->executeReadWriteCommand(DATABASE_NAME, $command, ['session' => $session]);

0 commit comments

Comments
 (0)