2

I am trying to integrate mongodb to an application I am developing with Laravel 5.2. I have mongodb installed on my computer and the php driver working correctly (I have a standalone php file with a very basic connection to my database and the results are brought correctly).

As the application will work as a REST API, I created a very basic function that will return all the documents in the collection in the database but I get this error:

ConnectionTimeoutException in Collection.php line 437:
No suitable servers found (`serverselectiontryonce` set): [connection timeout calling ismaster on '127.0.0.1:3306']

I used both the Eloquent as well as the DB approach but the result is the same.

The code belongs to the Collection.php file inside the vendor/mongodb/mongodb/src/ folder and the line contains this:

$server = $this->manager->selectServer($options['readPreference']);

I'm using Mongo 3.2.7 and jenssegers/laravel-mongodb 3.0.x.

My standalone php file and the mongo shell work as they should and when I run pgrep mongod the process id is returned so I know it's working, but I can't get this to work within my Laravel 5.2 application.

Any ideas?

pgzm29
  • 160
  • 1
  • 13
  • 2
    you are trying to connect to mysql port `3306`. Input the correct mongodb port and it should work fine. I think it is `27017` – Cerlin Jul 04 '16 at 07:03
  • Oh yeah! I totally forgot to change it on the .env file, I modified that on the connection array but it was overwritten by the .env one. Thanks a lot! – pgzm29 Jul 04 '16 at 07:27
  • Now I'm just having some issues with the authentication, but from artisan tinker it works correctly so it's almost ready to go – pgzm29 Jul 04 '16 at 07:28

0 Answers0