mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-03-29 12:22:07 +02:00
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).
65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
--TEST--
|
|
MongoDB\Driver\Manager::executeReadWriteCommand() pins transaction to server
|
|
--SKIPIF--
|
|
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
|
|
<?php skip_if_not_mongos_with_replica_set(); ?>
|
|
<?php skip_if_server_version('<', '4.1.6'); ?>
|
|
<?php skip_if_not_clean(); ?>
|
|
--FILE--
|
|
<?php
|
|
require_once __DIR__ . "/../utils/basic.inc";
|
|
|
|
$manager = new MongoDB\Driver\Manager(URI);
|
|
|
|
/* Create collections as that can't be (automatically) done in a transaction */
|
|
$manager->executeCommand(
|
|
DATABASE_NAME,
|
|
new \MongoDB\Driver\Command([ 'create' => COLLECTION_NAME ]),
|
|
[ 'writeConcern' => new \MongoDB\Driver\WriteConcern( \MongoDB\Driver\WriteConcern::MAJORITY ) ]
|
|
);
|
|
|
|
$session = $manager->startSession();
|
|
var_dump($session->getServer() instanceof \MongoDB\Driver\Server);
|
|
|
|
$session->startTransaction();
|
|
var_dump($session->getServer() instanceof \MongoDB\Driver\Server);
|
|
|
|
$command = new MongoDB\Driver\Command([
|
|
'aggregate' => COLLECTION_NAME,
|
|
'pipeline' => [
|
|
['$group' => ['_id' => 1]],
|
|
/* Note: $out cannot be used in a transaction. This is technically not a
|
|
* write command, but it works for the purposes of this test. */
|
|
],
|
|
'cursor' => (object) []
|
|
]);
|
|
$manager->executeReadWriteCommand(DATABASE_NAME, $command, ['session' => $session]);
|
|
|
|
$pinnedServer = $session->getServer();
|
|
var_dump($pinnedServer instanceof \MongoDB\Driver\Server);
|
|
|
|
$bulk = new MongoDB\Driver\BulkWrite();
|
|
$bulk->insert(['x' => 1]);
|
|
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
|
|
|
|
$session->commitTransaction();
|
|
|
|
var_dump($session->getServer() == $pinnedServer);
|
|
|
|
$bulk = new MongoDB\Driver\BulkWrite();
|
|
$bulk->insert(['x' => 1]);
|
|
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
|
|
|
|
var_dump($session->getServer() instanceof \MongoDB\Driver\Server);
|
|
|
|
?>
|
|
===DONE===
|
|
<?php exit(0); ?>
|
|
--EXPECT--
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|
|
bool(false)
|
|
===DONE===
|