use MongoDB\Driver\ReadConcern, MongoDB\Driver\WriteConcern;
$items = $client->selectDatabase(
'test',
[
'readConcern' => new ReadConcern(ReadConcern::MAJORITY),
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
]
)->items;
$s1 = $client->startSession(
[ 'causalConsistency' => true ]
);
$currentDate = new \MongoDB\BSON\UTCDateTime();
$items->updateOne(
[ 'sku' => '111', 'end' => [ '$exists' => false ] ],
[ '$set' => [ 'end' => $currentDate ] ],
[ 'session' => $s1 ]
);
$items->insertOne(
[ 'sku' => '111-nuts', 'name' => 'Pecans', 'start' => $currentDate ],
[ 'session' => $s1 ]
);