3

When I'm, trying to run php artisan queue:work command, I'm getting this error:

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function beginTransaction() on null

I have checked almost all the available help for this error on the internet, but I didn't get any solution.

I'm not sure if this has something to do with this package which I'm using.

https://github.com/jenssegers/laravel-mongodb

I'm guessing it might be as someone else also got this error, but unfortunately there are no any replies.

https://github.com/jenssegers/laravel-mongodb/issues/964

Detail error from the log:

[2016-11-12 20:18:45] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function beginTransaction() on null' in C:\wamp\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:611
Stack trace:
#0 {main}  

Any help would be appreciated.

Thanks in advance.

Thanks,

Parth vora

Parth Vora
  • 4,073
  • 7
  • 36
  • 59

3 Answers3

7

I also had the problem with the DB::beginTransaction() method. Following snippet solved my problem

$session = DB::getMongoClient()->startSession();
$session->startTransaction();
try {
    // Perform actions.
    $session->commitTransaction();
} catch(Exception $e) {
    $session->abortTransaction();
}

Thanks to this answer.


BTW I am using MongoDB version 4.0.3 and tested on Laravel version 5.7 and 5.8

Community
  • 1
  • 1
Salal Aslam
  • 1,367
  • 4
  • 16
  • 32
3

I have found the issue.

I had not followed the queue configuration of the package.

https://github.com/jenssegers/laravel-mongodb#queues

Just follow the proper instruction and it works very well.

Parth Vora
  • 4,073
  • 7
  • 36
  • 59
  • Hi @Parth Vora. I have upgraded from laravel 5.4.23 to 5.4.24 and now I am facing this same issue. I am using database as queue driver. What can I do to fix it? – Fokwa Best Jun 02 '17 at 06:37
0

I researched and realized it was related with MySQL/MariaDB being "killed to free memory". So I restarted the server with sudo shutdown -r on cent os rhel 7 and started mysql/mariadb using sudo systemctl restart mariadb.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
shillary
  • 19
  • 1