Laravel 5.2 Mongo MonogDB无法解析MongoDB URI

时间:2017-03-01 13:44:34

标签: php mongodb laravel laravel-5 laravel-5.2

我收到此错误:

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

我的环境变量如下所示:

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

我的database.php看起来像这样

'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
    ]

我可以正确地从容器中ping mongo,并根据连接字符串解析为172.17.0.3。似乎连接字符串的其余部分未正确生成?

我正在运行Laravel 5.2而我的package.json有此条目

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

根据https://github.com/jenssegers/laravel-mongodb 3.0.XLaravel 5.2的兼容性最高。

非常感谢提前

1 个答案:

答案 0 :(得分:0)

经过进一步调查后,来自Amazon ECS的链接传递了另一个MONGO_PORT,该.env覆盖了<form data-sc-id="Uploader" data-sc-databasename="master" data-sc-maxrequestlength="-1024" data-sc-executiontimeout="600" data-sc-destinationurl="/sitecore/media library/Images/Social/Connector/download" data-sc-filesizeexceededtext="The maximum amount of data that you can upload is" data-sc-timeoutext="The media files could not be uploaded. Please try again." class="sc-uploader row sc_Uploader_42 data-sc-registered" data-sc-require="/-/speak/v1/business/uploader.js" method="POST" enctype="multipart/form-data"> <img class="sc-uploader-preview hide"> <div class="sc-uploader-content"> <span class="drag"> Drag and drop files here <br> or <br> </span> <a href="#" class="btn btn-default sc-button sc_Button_14 data-sc-registered"> Browse for media files <input class="sc-uploader-fileupload" type="file" name="files[]" multiple="" data-url="/api/sitecore/Media/Upload? database=master&amp;destinationUrl=/sitecore/media library/Images/Social/Connector/download"> </a> <div class="sc-uploader-general-info"> <div class="sc-uploader-general-info-progressbar progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="display: none;"> <div class="bar data-sc-registered" data-bind="style: { width: globalPercentage() + '%' }" style="width: 0%;"></div> </div> <div class="sc-uploader-general-info-data" style="display: block;"> <div class="sc-uploader-general-info-data-col col1"> <div class="sc-uploader-general-info-data-uploadingData" style="display: none;"><span data-bind="text: uploadedSize" class="data-sc- registered">0</span>&nbsp;of&nbsp;</div><span data-bind=" text: totalSize" class="data-sc-registered">11.2 Kb</span> </div> <div class="sc-uploader-general-info-data-col col2">|</div> <div class="sc-uploader-general-info-data-col col3"> <div class="sc-uploader-general-info-data-uploadingData" style="display: none;"> <span data-bind=" text: uploadedFiles" class="data-sc-registered">0</span> &nbsp;of&nbsp; </div> <span data-bind=" text: totalFiles" class="data-sc-registered">1</span>&nbsp;<span data-bind=" visible: totalFiles() > 1" class="data-sc-registered" style="display: none;">Files</span> <span data-bind=" visible: totalFiles() === 1" class="data-sc-registered">File</span> </div> </div> </div> </div> </form> 文件中设置的env。