使用Compose.io在Laravel中设置mongodb配置

时间:2017-06-13 07:56:32

标签: mongodb laravel-5 compose.io

我第一次使用compose.io作为我的mongodb托管。

我试图用Laravel配置compose.io mongodb,但最终出现了这个错误:

ConnectionTimeoutException in Collection.php line 432:
No suitable servers found (`serverSelectionTryOnce` set)

我正在使用https://github.com/jenssegers/laravel-mongodb包向Laravel添加mongodb支持。

我的mongodb配置:

   'mongodb' => [
        'driver'   => 'mongodb',
        'host' => ['aws-us-east-1-portal.25.dblayer.com:20020/admin', 'aws-us-east-1-portal.26.dblayer.com:20020/admin'],
        'port'     => env('MONGO_DB_PORT', 27017),
        'database' => env('MONGO_DB_DATABASE'),
        'username' => env('MONGO_DB_USERNAME'),
        'password' => env('MONGO_DB_PASSWORD'),
        'options'  => [
            'ssl' => true,
            'database' => 'admin', // sets the authentication database required by mongo 3
            'replicaSet' => 'set-5939226a8aab5300121d0ef2',
            'readPreference' => 'primary',
        ],
        'driver_options' => [
            'context' => stream_context_create( [
                'ssl' => [
                    'local_cert' =>  base_path('mongo.pem'),
                    'cafile'     =>  base_path('mongo.pem'),
                    'allow_self_signed' => true,
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                    'verify_expiry'     => false,
                    'allow_invalid_certificates'  => true
                ]

            ])
        ]
    ]

我不确定 MONGO_REPLICA_SET

的价值是多少?

任何人都有类似的经历吗?

由于

1 个答案:

答案 0 :(得分:0)

它的工作原理是删除replicaSet选项

最终配置:

'mongodb' => [
        'driver'   => 'mongodb',
        'host' => ['aws-us-east-1-portal.25.dblayer.com', 'aws-us-east-1-portal.26.dblayer.com'],
        'port'     => env('MONGO_DB_PORT', 27017),
        'database' => env('MONGO_DB_DATABASE'),
        'username' => env('MONGO_DB_USERNAME'),
        'password' => env('MONGO_DB_PASSWORD'),
        'options'  => [
            'ssl' => true,
            'database' => env('MONGO_DB_DATABASE'), // sets the authentication database required by mongo 3
        ],
        'driver_options' => [
            'context' => stream_context_create( [
                'ssl' => [
                    'cafile'     =>  base_path('mongo.pem'),
                    'allow_self_signed' => true,
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                    'verify_expiry'     => false,
                ]

            ])
        ]
    ]