Closed
Description
- Laravel-mongodb Version: 4.1
- PHP Version: 8.2.15
- Database Driver & Version: db version v6.0.13
- PHP MongoDB extension version 1.17.2
Description:
Using firstOrCreate() in a transaction returns an error
Steps to reproduce
$mongodb = DB::connection('app');
$mongodb->beginTransaction();
// user does not exist and will be created
\App\Models\User::firstOrCreate(['username' => 'johncarpenter', 'name' => 'carpenter', 'email' => '[email protected]']);
$mongodb->rollBack();
Expected behaviour
Manage transaction and commit or rollBack
Actual behaviour
retuns error :
local.ERROR: MongoDB\Driver\Exception\RuntimeException: Transaction already in progress in vendor/mongodb/mongodb/src/Operation/WithTransaction.php:60
Notes
create() works fine
firstOrCreate() and updateOrCreate() do work for updates but do not work for creation as they start a transaction in vendor/mongodb/mongodb/src/Operation/WithTransaction.php
Hack
We went through adding a test in vendor/mongodb/mongodb/src/Operation/WithTransaction.php
if (!$session->isInTransaction()) {
$session->startTransaction($this->transactionOptions);
}