Laravel 5.2 Mongo MonogDB Failed to parse MongoDB URI

时间秒杀一切 提交于 2019-12-11 08:28:20

问题


I am getting this error:

MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb://mongo:tcp://172.17.0.3:27017/mydatabase' in /var/www/laravel/vendor/mongodb/mongodb/src/Client.php:81

My enviroment variables look like this:

MONGO_DATABASE="mydatabase"
MONGO_HOST="mongo"
MONGO_PASSWORD=""
MONGO_PORT="27017"
MONGO_USERNAME=""

and my database.php looks like this

'mongodb' => [
    'driver'   => 'mongodb',
    'host'     => env('MONGO_HOST', 'localhost'),
    'port'     => env('MONGO_PORT', 27017),
    'database' => env('MONGO_DATABASE', 'mydatabase'),
    'username' => env('MONGO_USERNAME', ''),
    'password' => env('MONGO_PASSWORD', ''),
    'options' => [
        'database' => 'admin' // sets the authentication database required by mongo 3
    ]

I can correctly ping mongo from the container and it resolves to 172.17.0.3 as per the connection string. It seems as if the rest of the connection string is not getting generated correct?

I am running Laravel 5.2 and my package.json has this entry

"mongodb/mongodb": "^1.0.0",
"jenssegers/mongodb": "3.0.*",

As per https://github.com/jenssegers/laravel-mongodb 3.0.X is highest compatibility for Laravel 5.2.

Many thanks in advance


回答1:


After further investigation my link from Amazon ECS was passing another MONGO_PORT which was overriding the env set in my .env file.



来源:https://stackoverflow.com/questions/42533402/laravel-5-2-mongo-monogdb-failed-to-parse-mongodb-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!