Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel mongodb closing client connection remaining data too small

Route::get('/', function () {
    $tweets = Tweet::all();
    return view('welcome', ['tweets' => $tweets]);
});

I am making a laravel app using mongodb.

When I go to '/', I get an error in the mongod terminal that says

AssertionException handling request, closing client connection: 10304 Client Error: Remaining data too small for BSON object

This is my tweet model (in App\Tweet):

namespace App;

use Jenssegers\Mongodb\Model as Eloquent;

class Tweet extends Eloquent {

    protected $collection = 'tweets_collection';

}
like image 349
jim rectenwald Avatar asked Oct 31 '22 12:10

jim rectenwald


1 Answers

There are at least two reasons why this issue (Client Error: Remaining data too small for BSON object) appears:

1. PHP MongoDB driver is not compatible with MongoDB installed on the machine.
(originally mentioned in the first answer).

Examine PHP driver version set up on your machine on <?php phpinfo(); page:

enter image description here

Retrieve MongoDB version in use with:

mongod --version\
# db version v3.2.0

Use compatibility table on MongoDB website to see whether examined PHP MongoDB driver version is compatible with MongoDB version:

enter image description here

If versions are not compatible, it is required to uninstall one of the existing parts and install compatible version. From my own experience, it is much easier to change PHP MongoDB driver, since only different .so extension file is required.

2. Two PHP MongoDB drivers are installed on the machine.

Since MongoClient is deprecated, many tutorials and articles online (including official mongo-php-driver repository on Github) now guides to install mongodb, not mongo PHP driver. Year+ before, everyone was pointing at mongo extension, however.

Because of this change from mongo to mongodb, we might get both extensions defined in php.ini file. Just make sure, only one extension is defined under "Dynamic Extension" section:

enter image description here


Hope somebody gets this answer useful when looking for a solution to fix "Remaining data too small for BSON object" error working with MongoDB through PHP MongoDB driver.

like image 117
Nik Sumeiko Avatar answered Nov 09 '22 13:11

Nik Sumeiko