Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Exception: Server reports wire version 0, but version of libmongoc requires at least 3

Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionException: Server at localhost:27017 reports wire version 0, but this version of libmongoc requires at least 3 (MongoDB 3.0)

I have PHP 7.0.13, MAMP and MongoDB. The MongoDB extension for PHP has been installed.

I have the following:

<?php

ini_set('display_errors', 'On');
require 'vendor/autoload.php';
var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";

$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");

// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));

// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $m->executeQuery('testDb.testColl', $query);

// Convert cursor to Array and print result
print_r($cursor->toArray());

?>

What does 'wire' refer to in this context, and does anyone have a solution for this problem?

like image 331
Weirdali Avatar asked Oct 05 '18 16:10

Weirdali


2 Answers

I have got the problem on Linux Mint 19 (think that Ubuntu 18+ can have the same problem):

Server at IP:27017 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)

As the message says - server driver version and mine one are different. This happened because I installed php mongo driver with the command:

sudo apt-get install php7.2-mongodb

The SOLUTION was to completely uninstall php mongo driver:

sudo apt-get remove --auto-remove php-mongodb

and then install php-mongodb from Pecl mongodb php extension:

sudo pecl install mongodb-1.4.4

(If you bump into error pecl: command not found, just install PEAR package in order to use pecl installer. sudo apt-get update && sudo apt-get install php-pear)

After that add the next line to your php.ini file:

extension=mongodb.so

Don't forget to reload the web server:

sudo systemctl reload apache2

That's it. Everything should work!

like image 138
Evgeny Melnikov Avatar answered Sep 21 '22 18:09

Evgeny Melnikov


I have a Raspberry Pi 3B with mongo version. It runs an older version of MongoDB, so I found an equally old version of pymongo and it worked.

mongo --version
MongoDB shell version: 2.4.14

min_wire_version was added sometime after the release of Mongo 2.4.14, so I just installed pymongo drivers that were equally as old.

pip install pymongo==2.4.2 worked for me.

like image 20
JustinDanielson Avatar answered Sep 18 '22 18:09

JustinDanielson