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());
?>
在这种情况下“电线”指的是什么?有人有解决这个问题的办法吗?
我在 Linux Mint 19 上遇到了这个问题(认为 Ubuntu 18+ 也可能有同样的问题):
IP:27017 的服务器报告线路版本 2,但此版本的 libmongoc 至少需要 3 (MongoDB 3.0)
正如消息所说 - 服务器驱动程序版本和我的版本不同。
发生这种情况是因为我使用以下命令安装了 php mongo 驱动程序:
sudo apt-get install php7.2-mongodb
The SOLUTION是完全卸载 php mongo 驱动程序:
sudo apt-get remove --auto-remove php-mongodb
然后安装 php-mongodbPecl mongodb php 扩展:
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
file:
extension=mongodb.so
不要忘记重新加载网络服务器:
sudo systemctl reload apache2
就是这样。一切都应该有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)