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';
}
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:
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:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With