xp-forge / mongodb

MongoDB for the XP Framework
0 stars 0 forks source link

Support transactions #12

Closed thekid closed 2 years ago

thekid commented 2 years ago

ACID Transactions in MongoDB

use com\mongodb\MongoConnection;

$c= new MongoConnection('mongodb+srv://server.example.com');

$transaction= $c->session()->transaction();

$collection->update($id1, ['$inc' => ['qty' => -1]], $transaction);
$collection->update($id2, ['$inc' => ['qty' => 1]], $transaction);

$transaction->commit();  // or $transaction->abort();

See https://www.mongodb.com/transactions

thekid commented 2 years ago

Initial support in https://github.com/xp-forge/mongodb/releases/tag/v0.10.0