PHP code example of pccomponentes / mongodb-transaction

1. Go to this page and download the library: Download pccomponentes/mongodb-transaction library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pccomponentes / mongodb-transaction example snippets




$client = new PcComponentes\Transaction\Driver\MongoDB\Client($uri);

try {
    $client->beginTransaction();
    //...
    $client->commit();
} catch (\Throwable $exception) {
    $client->rollBack();
}



$middleware = new PcComponentes\Transaction\SymfonyMessenger\TransactionMiddleware(
    new PcComponentes\Transaction\Driver\MongoDB\MongoDBTransactionalConnection(
        new PcComponentes\Transaction\Driver\MongoDB\Client($uri)
    )
);