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扩展.
I have PHP 7.0.13, MAMP and MongoDB. The MongoDB extension for PHP has been installed.
我有以下内容:
<?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?
推荐答案
我在Linux Mint 19上遇到了问题(认为Ubuntu 18+可能有同样的问题):
I have got the problem on Linux Mint 19 (think that Ubuntu 18+ can have the same problem):
IP:27017的服务器报告的有线版本为2,但是此版本的libmongoc至少需要3(MongoDB 3.0)
Server at IP:27017 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)
如消息所示-服务器驱动程序版本与我的驱动程序版本不同. 发生这种情况是因为我使用以下命令安装了php mongo驱动程序:
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
解决方案是要完全卸载php mongo驱动程序:
The SOLUTION was to completely uninstall php mongo driver:
sudo apt-get remove --auto-remove php-mongodb
,然后从 Pecl mongodb php扩展名安装:
and then install php-mongodb from Pecl mongodb php extension:
sudo pecl install mongodb-1.4.4
(如果遇到错误pecl: command not found
,只需安装PEAR软件包即可使用pecl
安装程序.sudo apt-get update && sudo apt-get install php-pear
)
(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
)
之后,将下一行添加到您的php.ini
文件中:
After that add the next line to your php.ini
file:
extension=mongodb.so
别忘了重新加载Web服务器:
Don't forget to reload the web server:
sudo systemctl reload apache2
就是这样.一切都会正常!
That's it. Everything should work!
这篇关于MongoDB异常:服务器报告的连线版本为0,但libmongoc的版本至少需要3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!