MongoDB 异常:服务器报告线路版本 0,但 libmongoc 版本至少需要 3
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)
我有 PHP 7.0.13、MAMP 和 MongoDB。 PHP 的 MongoDB 扩展已安装。
我有以下内容:
<?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());
?>
在这种情况下,'wire' 指的是什么,有人对此问题有解决方案吗?
我在 Linux Mint 19 上遇到了问题(认为 Ubuntu 18+ 可能有同样的问题):
Server at IP:27017 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)
正如消息所说 - 服务器驱动程序版本和我的不同。
发生这种情况是因为我使用以下命令安装了 php mongo 驱动程序:
sudo apt-get install php7.2-mongodb
解决方案 是完全卸载 php mongo 驱动程序:
sudo apt-get remove --auto-remove php-mongodb
然后从 Pecl mongodb php extension:
安装 php-mongodb
sudo pecl install mongodb-1.4.4
(如果遇到错误 pecl: command not found
,只需安装 PEAR 包即可使用 pecl
安装程序。sudo apt-get update && sudo apt-get install php-pear
)
之后,将下一行添加到您的 php.ini
文件中:
extension=mongodb.so
不要忘记重新加载网络服务器:
sudo systemctl reload apache2
就是这样。一切正常!
我有一个 Raspberry Pi 3B mongo 版本。它运行旧版本的 MongoDB,所以我找到了一个同样旧版本的 pymongo 并且它有效。
mongo --version
MongoDB shell version: 2.4.14
min_wire_version
是在 Mongo 2.4.14 发布后的某个时间添加的,所以我只安装了同样旧的 pymongo 驱动程序。
pip install pymongo==2.4.2
为我工作。
如果有人正在寻找 Centos 7 的解决方案,这就是您需要做的(基于 Evgeny Melnikov 的回答):
yum erase php-pecl-mongodb && pecl uninstall mongodb
pecl install mongodb-1.9.1
然后将扩展名=mongodb.so 添加到您的 php.ini 文件并重新启动 php-fpm。
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)
我有 PHP 7.0.13、MAMP 和 MongoDB。 PHP 的 MongoDB 扩展已安装。
我有以下内容:
<?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());
?>
在这种情况下,'wire' 指的是什么,有人对此问题有解决方案吗?
我在 Linux Mint 19 上遇到了问题(认为 Ubuntu 18+ 可能有同样的问题):
Server at IP:27017 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)
正如消息所说 - 服务器驱动程序版本和我的不同。 发生这种情况是因为我使用以下命令安装了 php mongo 驱动程序:
sudo apt-get install php7.2-mongodb
解决方案 是完全卸载 php mongo 驱动程序:
sudo apt-get remove --auto-remove php-mongodb
然后从 Pecl mongodb php extension:
安装 php-mongodbsudo pecl install mongodb-1.4.4
(如果遇到错误 pecl: command not found
,只需安装 PEAR 包即可使用 pecl
安装程序。sudo apt-get update && sudo apt-get install php-pear
)
之后,将下一行添加到您的 php.ini
文件中:
extension=mongodb.so
不要忘记重新加载网络服务器:
sudo systemctl reload apache2
就是这样。一切正常!
我有一个 Raspberry Pi 3B mongo 版本。它运行旧版本的 MongoDB,所以我找到了一个同样旧版本的 pymongo 并且它有效。
mongo --version
MongoDB shell version: 2.4.14
min_wire_version
是在 Mongo 2.4.14 发布后的某个时间添加的,所以我只安装了同样旧的 pymongo 驱动程序。
pip install pymongo==2.4.2
为我工作。
如果有人正在寻找 Centos 7 的解决方案,这就是您需要做的(基于 Evgeny Melnikov 的回答):
yum erase php-pecl-mongodb && pecl uninstall mongodb
pecl install mongodb-1.9.1
然后将扩展名=mongodb.so 添加到您的 php.ini 文件并重新启动 php-fpm。