title: Laravel mongodb transactions
body: <p>I need to use transactions on MongoDB in Laravel.</p>
  
  <p>I downloaded the php MongoDB driver 1.6 and copied and pasted php_mongodb.dll into the php/ext folder.</p>
  
  <p>I also installed the php mongo library through</p>
  
  <pre><code>composer require mongodb/mongodb
  </code></pre>
  
  <p>Now, when I try to use transactions according to <a href="https://docs.mongodb.com/manual/core/transactions/index.html" rel="nofollow noreferrer">this</a>, it doesn't rollback when an error occurs. </p>
  
  <pre><code>   $client = new Client($url);
      $callback = function (\MongoDB\Driver\Session $session) use ($client) {
          $data = [
              "name" =&gt; "Tommy",
                       ];
          $collection = $client-&gt;db1-&gt;users;
          $user = $collection-&gt;updateOne(
              ['mobile' =&gt; '*'],
              ['$set' =&gt; $data],
              [$session]
          );
          $data = [
              "activate" =&gt; 1,
          ];
          $collection = $client-&gt;db1-&gt;wallets;
          $wallet1 = $collection-&gt;updateOne(
              ['_id' =&gt; 100],
              ['set' =&gt; $data],
              [$session]
          );
  
      };
  
      $session = $client-&gt;startSession();
      $transactionOptions = [
          'readConcern' =&gt; new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL),
          'writeConcern' =&gt; new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY, 1000),
          'readPreference' =&gt; new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_PRIMARY),
      ];
  
      try{
          \MongoDB\with_transaction($session, $callback, $transactionOptions);
          return true;
  
      }catch (\Exception $e)
      {
          return false;
      }
  </code></pre>
  
  <p>The session class in <code>MongoDB\Driver\Session</code> is unknown in laravel while this class is for mongodb>=1.4.0. I don't know what is wrong. Can anyone help me?</p>