Closed thekid closed 2 years ago
Implements #12:
use com\mongodb\MongoConnection; $c= new MongoConnection('mongodb+srv://server.example.com'); $transaction= $c->session()->transaction(); // Update two documents $collection->update($id1, ['$inc' => ['qty' => -1]], $transaction); $collection->update($id2, ['$inc' => ['qty' => 1]], $transaction); // Reads changed values Console::writeLine('Inside: ', [...$collection->find(['qty' => ['$exists' => true]], $transaction)]); $transaction->commit(); // or $transaction->abort(); // Reads committed values, original values if aborted Console::writeLine('Outside: ', [...$collection->find(['qty' => ['$exists' => true]])]);
Implements #12: