0

I am working with the Laravel framework and using MongoDB. So I need to commit and roll back the collection save, but I get the following error in response.

Server does not support sessions

Does my MongoDB installation not support sessions? If not, how can I enable sessions?

$session = DB::getMongoClient()->startSession();
$session->startTransaction();
try {  
    // Query
    $lead = Leads::create($data);
    $session->commitTransaction();
} catch (\Exception $e) {
    $session->abortTransaction();
}

This is the version of Mongodb I am using mongodb-win32-x86_64-2008plus-ssl-3.4.24-3-g78e64a697a Just copied to bin and running

B L Praveen
  • 1,812
  • 4
  • 35
  • 60

1 Answers1

0

Most probably you connect to single mongoDB instance. You need to connect to replicaSet with version >= 4.0 to support transactions+sessions. For sharded cluster you need version >= 4.2 at least to support transactions+sessions. For development/testing you can convert your single mongodb deployment at least to replicaSet with single PRIMARY for mongodb version>=4.0.

R2D2
  • 9,410
  • 2
  • 12
  • 28