我是laravel中使用MongoDB的新手,我想在MongoDB中使用laravel 4.2,但我遇到了这个问题:
> C:\xampp\htdocs\laravel-mongo>composer require jenssegers/mongodb Using version ^3.0 for jenssegers/mongodb ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - jenssegers/mongodb v3.0.0 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1]. - jenssegers/mongodb v3.0.1 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1]. - jenssegers/mongodb v3.0.2 requires mongodb/mongodb ^1.0.0 -> satisfiable by mongodb/mongodb[1.0.0, 1.0.1]. - mongodb/mongodb 1.0.1 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb has the wrong version (1.0.0) installed. - mongodb/mongodb 1.0.0 requires ext-mongodb ^1.1.0 -> the requested PHP extension mongodb has the wrong version (1.0.0) installed. - Installation request for jenssegers/mongodb ^3.0 -> satisfiable by jenssegers/mongodb[v3.0.0, v3.0.1, v3.0.2]. To enable extensions, verify that they are enabled in those .ini files: - C:\xampp\php\php.ini You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode. Installation failed, reverting ./composer.json to its original content.
答案 0 :(得分:1)
对于Laravel 4.2,您需要2.0.x version的包
composer require jenssegers/mongodb ^2.0
当您没有指定版本时,默认情况下,编辑器会抓取最新的稳定版本,目前恰好是v3.0.2。
答案 1 :(得分:1)
由于旧的mongo安装,这发生在我身上(对于Lumen 5)。
来自http://php.net/manual/en/class.mongoclient.php:
警告:不推荐使用此扩展来定义此类。代替, 应该使用MongoDB扩展。
按照接下来的步骤,我可以让jenssegers/mongodb
正常工作:
sudo apt-get install php5-dev
sudo pecl install mongodb
然后添加到/etc/php5/cli/php.ini
或类似名称:
extension=mongodb.so
然后安装驱动程序
composer require jenssegers/mongodb
参考:http://haafiz.me/development/installing-mongodb-driver-mongoclient-for-php-on-ubuntu