无法解析 MongoDB URI:'mongodb://'。 URI 中的主机字符串无效
Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI
尝试 运行 MongoDB 4.0 和 laravel 时出现以下错误
PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException:
Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI. in /var/www/html/valueableapp/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php:87`
我使用命令 mongo
到 运行 mongo shell 并且它工作正常。
还有 sudo service mongod status
并且它还显示状态 运行ning。
我什至无法开始我的项目。这是我遇到的问题的完整堆栈跟踪
php artisan 服务 --port=8080
Laravel development server started: http://127.0.0.1:8080
[Wed May 22 10:00:54 2019] PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI. in /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php:87
Stack trace:
#0 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php(87): MongoDB\Driver\Manager->__construct('mongodb://', Array, Array)
#1 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php(141): MongoDB\Client->__construct('mongodb://', Array, Array)
#2 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php(41): Jenssegers\Mongodb\Connection->createConnection('mongodb://', Array, Array)
#3 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/MongodbServiceProvider.php(30): Jenssegers\Mongodb\Connection->__construct(Array)
#4 [internal function]: Jenssegers\Mongo in /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php on line 87
Config/database.php
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default'=>'mongodb',
'connections' => array(
'mongodb' => array(
'driver' => 'mongodb',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'database' => env('DB_DATABASE'),
'options' => [
'database' => env('DB_DATABASE')
]
),
),
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:q0DOPnhqUzhmMrqryyyN6SDOi6NHKh/BbmJGHw35e3E=
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=abc
DB_USERNAME=
DB_PASSWORD=
CACHE_DRIVER=array
SESSION_DRIVER=file
QUEUE_DRIVER=sync
CRITERIA_MAX_SCORE=5
CRITERIA_MIN_SCORE=1
MAX_SCORE_APP=1000
提前致谢。我在这个网站上寻找解决方案
但是这个问题没有答案。
就我而言,我只是解决了它,但将文件名从 .env
更改为 .env.local
。
谢谢
由于端口号错误,我遇到了这个错误。请先确认
尝试 运行 MongoDB 4.0 和 laravel 时出现以下错误
PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI. in /var/www/html/valueableapp/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php:87`
我使用命令 mongo
到 运行 mongo shell 并且它工作正常。
还有 sudo service mongod status
并且它还显示状态 运行ning。
我什至无法开始我的项目。这是我遇到的问题的完整堆栈跟踪
php artisan 服务 --port=8080
Laravel development server started: http://127.0.0.1:8080 [Wed May 22 10:00:54 2019] PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI. in /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php:87 Stack trace: #0 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php(87): MongoDB\Driver\Manager->__construct('mongodb://', Array, Array) #1 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php(141): MongoDB\Client->__construct('mongodb://', Array, Array) #2 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php(41): Jenssegers\Mongodb\Connection->createConnection('mongodb://', Array, Array) #3 /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/MongodbServiceProvider.php(30): Jenssegers\Mongodb\Connection->__construct(Array) #4 [internal function]: Jenssegers\Mongo in /var/www/html/valueable-app/valueable_rest_app/api_src/vendor/mongodb/mongodb/src/Client.php on line 87
Config/database.php
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default'=>'mongodb',
'connections' => array(
'mongodb' => array(
'driver' => 'mongodb',
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'database' => env('DB_DATABASE'),
'options' => [
'database' => env('DB_DATABASE')
]
),
),
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:q0DOPnhqUzhmMrqryyyN6SDOi6NHKh/BbmJGHw35e3E=
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=abc
DB_USERNAME=
DB_PASSWORD=
CACHE_DRIVER=array
SESSION_DRIVER=file
QUEUE_DRIVER=sync
CRITERIA_MAX_SCORE=5
CRITERIA_MIN_SCORE=1
MAX_SCORE_APP=1000
提前致谢。我在这个网站上寻找解决方案
就我而言,我只是解决了它,但将文件名从 .env
更改为 .env.local
。
谢谢
由于端口号错误,我遇到了这个错误。请先确认