1

Its my first time use compose.io as my mongodb hosting.

I was trying to configure compose.io mongodb with Laravel but ended up this error:

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

I was using https://github.com/jenssegers/laravel-mongodb package to add mongodb support to Laravel.

My mongodb config:

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

            ])
        ]
    ]

I am not also sure what is the value for MONGO_REPLICA_SET

Anyone experienced something similar?

Thanks

arjayads
  • 553
  • 1
  • 5
  • 17
  • What is the question? What you supply for the connection strings? The code above is looking at environment variables, so what is the content of those variables? – Neil Lunn Jun 13 '17 at 08:02
  • Based on the error, what are the possibilities? – arjayads Jun 13 '17 at 08:05
  • I just told you. Show us the connection strings. They appear to be stored in environment variables. Or quite possibly you missed documented steps and never set the values. – Neil Lunn Jun 13 '17 at 08:07
  • okk fine .. Now Can You Show The COde Of .env File ... So Can Understand... easily ... – RïshïKêsh Kümar Jun 13 '17 at 08:11
  • @NeilLunn Updated the config – arjayads Jun 13 '17 at 09:35
  • A quick look at github issues would suggest to just use the "hostnames" only in the array like `['aws-us-east-1-portal.25.dblayer.com','aws-us-east-1-portal.26.dblayer.com']` and then change the `'port' => 20020`. For the next `'database'` line, you should set to the namespace for your app to use. You pasted in URI's with `admin` in them. But that is certainly not what you want. You should make sure that you have a user set up on a database namespace for the application and also add the username and password options. This is really just what the documentation says. So I would follow it. – Neil Lunn Jun 13 '17 at 09:45
  • @NeilLunn I have user created as database owner. I also added username and password to options. What do you mean by database namespace for the application. Can you please link me to the doc that says about the issue? – arjayads Jun 13 '17 at 10:07
  • I mean don't use "admin" since that space is where usernames etc are stored. Your application should be using something like "app" or whatever you want to call it. Bu don't use "admin" since that has it's own purpose. – Neil Lunn Jun 13 '17 at 10:08
  • Already changed the db to rid of admin @NeilLunn – arjayads Jun 13 '17 at 10:11
  • Update the configuration in your question to reflect and update any specific error messages you are getting. – Neil Lunn Jun 13 '17 at 10:15
  • Answered my the post. Thanks @NeilLunn for the hints – arjayads Jun 13 '17 at 10:23

1 Answers1

1

It works by removing replicaSet option

Final configuration:

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

            ])
        ]
    ]
arjayads
  • 553
  • 1
  • 5
  • 17
  • `PHP Deprecated: MongoDB/Driver/Manager::__construct(): The "context" driver option is deprecated. in /var/app/current/vendor/mongodb/mongodb/src/Client.php on line 116` – Khaled AbuShqear Jul 27 '20 at 09:46