PHPackages                             pccomponentes/mongodb-transaction - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pccomponentes/mongodb-transaction

ActiveLibrary

pccomponentes/mongodb-transaction
=================================

MongoDB Transaction

v1.0.2(5y ago)0793MITPHPPHP ^7.4

Since Feb 17Pushed 5y ago5 watchersCompare

[ Source](https://github.com/PcComponentes/mongodb-transaction)[ Packagist](https://packagist.org/packages/pccomponentes/mongodb-transaction)[ RSS](/packages/pccomponentes-mongodb-transaction/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

MongoDB Transaction
===================

[](#mongodb-transaction)

The problem
-----------

[](#the-problem)

The way to use transactions in **MongoDB** differs from a typical relational database connection (MySQL, PostgreSQL, etc).

In MongoDB a session is generated and all operations must be associated to that **session**.

That means that for any write anywhere in the code you would have to send the **session associated with the transaction** to MongoDB.

The solution
------------

[](#the-solution)

It has been extended the **Client**, **Collection** and **Database** classes. Can generate a session and pass it to each class to control transactions from the beginning.

Usage
-----

[](#usage)

Instead of instantiating the original `\MongoDB\Client`, instantiate the `PcComponentes\Transaction\Driver\MongoDB\Client` class.

```
