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

5

9
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?

Cyanine answered 5/10, 2018 at 16:20 Comment(1)
What version of MongoDB server are you using? The error message indicates that your driver requires at least MongoDB 3.0 and your server appears to be an older or unknown version.Catima
E
17

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!

Evergreen answered 18/10, 2018 at 8:43 Comment(6)
If you need to install mongodb for several versions of php with pecl, the instalation is convoluted a bit. In short, switch versions of php, install and backup lib, as installing on another version will remove previous one.Monique
Per mongodb/mongo-php-library#569, mongodb-1.5.0 was the first version to bump its minimum server version requirement. I'm not sure what version of the driver exists in Linux Mint 19, but Ubuntu 18.04's php7.2-mongodb package is 1.3.x and would not encounter this exception. Nor would version 1.4.4, which your answer suggests installing via PECL. That said, I think the best advice would be to upgrade the MongoDB server (versions <3.0 are quite old) rather than downgrade the driver.Buseck
Unfortunately, I have no opportunity to upgrade the version. That's why I was ought to downgrade the version in order to have the application work. But of course, it's better to use new version. You are right =)Evergreen
It turned out I had multiple versions of mongodb installed and I had to fully uninstall both before reinstalling the latest version. Thank you!Cyanine
if previously you had install it with pecl, do following: sudo pecl uninstall mongodb && sudo pecl install mongodb-1.4.4Hauler
A related problem that I'm having: https://askubuntu.com/questions/1418808/server-at-localhost27017-reports-wire-version-5-but-this-version-of-libmongocPsychodiagnostics
T
2

If anyone searching for solution for Centos 7, here's what you need to do (based on Evgeny Melnikov answer):

yum erase php-pecl-mongodb && pecl uninstall mongodb
pecl install mongodb-1.9.1

Then add extension=mongodb.so to your php.ini file and restart php-fpm.

Transfer answered 24/5, 2022 at 15:1 Comment(0)
H
1

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.

Horwitz answered 15/11, 2020 at 6:13 Comment(0)
A
0

https://pecl.php.net/package-info.php?package=mongodb&version=1.13.0

pecl uninstall mongodb
pecl install mongodb-1.13.0
Advocation answered 19/9, 2022 at 21:39 Comment(0)
O
0

Please look at the driver compatibility with https://www.mongodb.com/docs/drivers/php/#compatibility-table-legend

Install the PHP MongoDB Driver According to the Mongo DB Server.

This will solve all the problems.

enter image description here

Outlaw answered 23/3, 2023 at 14:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.