Commit 7beed248 authored by Derick Rethans's avatar Derick Rethans

PHPLIB-382: Updated Causal Consistency example for docs

parent dc1665a6
...@@ -1411,11 +1411,10 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1411,11 +1411,10 @@ class DocumentationExamplesTest extends FunctionalTestCase
// Prep // Prep
$client = new Client($this->getUri()); $client = new Client($this->getUri());
$test = $client->selectDatabase( $items = $client->selectDatabase(
'test', 'test',
[ 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY) ] [ 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY) ]
); )->items;
$items = $client->test->items;
$items->drop(); $items->drop();
$items->insertOne( $items->insertOne(
...@@ -1423,17 +1422,27 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1423,17 +1422,27 @@ class DocumentationExamplesTest extends FunctionalTestCase
); );
// Start Causal Consistency Example 1 // Start Causal Consistency Example 1
$items = $client->selectDatabase(
'test',
[
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::MAJORITY),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000),
]
)->items;
$s1 = $client->startSession( $s1 = $client->startSession(
[ 'causalConsistency' => true ] [ 'causalConsistency' => true ]
); );
$currentDate = new \MongoDB\BSON\UTCDateTime();
$items->updateOne( $items->updateOne(
[ 'sku' => '111', 'end' => [ '$exists' => false ] ], [ 'sku' => '111', 'end' => [ '$exists' => false ] ],
[ '$currentDate' => [ 'end' => true ] ], [ '$set' => [ 'end' => $currentDate ] ],
[ 'session' => $s1 ] [ 'session' => $s1 ]
); );
$items->insertOne( $items->insertOne(
[ 'sku' => '111-nuts', 'name' => 'Pecans', 'start' => new \MongoDB\BSON\UTCDateTime() ], [ 'sku' => '111-nuts', 'name' => 'Pecans', 'start' => $currentDate ],
[ 'session' => $s1 ] [ 'session' => $s1 ]
); );
// End Causal Consistency Example 1 // End Causal Consistency Example 1
...@@ -1449,7 +1458,11 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1449,7 +1458,11 @@ class DocumentationExamplesTest extends FunctionalTestCase
$items = $client->selectDatabase( $items = $client->selectDatabase(
'test', 'test',
[ 'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY) ] [
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY),
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::MAJORITY),
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000)
]
)->items; )->items;
$result = $items->find( $result = $items->find(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment