Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Fail #22

Closed
felixcheruiyot opened this issue Aug 17, 2013 · 8 comments
Closed

Connection Fail #22

felixcheruiyot opened this issue Aug 17, 2013 · 8 comments

Comments

@felixcheruiyot
Copy link

I am trying to use Laravel-MongoDB in Laravel 4 but I run into this error

MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known 

From Laravel trace tool, this file is highlighted [/var/www/archels/vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/Connection.php] line 30-39

// Store configuration
$this->config = $config;
// Check for connection options
$options = array_get($config, 'options', array());
// Create connection
$this->connection = new MongoClient($this->getDsn($config), $options);
// Select database

This is how I do my connection

'mongodb' => array( 'driver' => 'mongodb', 'host' => '127.0.0.1', 'port' => 27017, 'username' => 'myusername', 'password' => 'mypassword', 'database' => 'mydb' ),

Note: I followed this tutorial for php-driver installation and RockDB.

Any Idea on why this is happening? Thanks

@jenssegers
Copy link
Contributor

I don't really know what is causing that warning, but I don't think it is related to the library as it is PHP's MongoClient that is throwing it. You could try localhost instead of 127.0.0.1.

Good luck.

@felixcheruiyot
Copy link
Author

Thank you for the response. I am still trying to solve these problem. I noticed that passing the connection string directly at line 37 works.

 $this->connection = new MongoClient('mongodb://localhost/');

This gives me an idea that my mongo works with php, but how is the current connection string look like? Can there be a problem with the way we are passing it. Here is my server details:

  • PHP 5.3.6
  • Ubuntu server
  • Laravel 4

Thanks

@jenssegers
Copy link
Contributor

It will generate the following DSN for the configuration array above:

mongodb://myusername:mypassword@127.0.0.1:27017/mydb

@felixcheruiyot
Copy link
Author

Found the problem. It is on my side. Used a password generator and which produced my password with a '@' character. Just noticed that. The code is working well.

I am now passing my connection as expected:

'mongodb' => array( 'driver' => 'mongodb', 'host' => '127.0.0.1', 'port' => 27017, 'username' => 'myusername', 'password' => 'mypassword', 'database' => 'mydb' ),

Thank you for the good library and support.

@jenssegers jenssegers reopened this Aug 17, 2013
@jenssegers
Copy link
Contributor

I will try passing the username and password as options to avoid this problem for future users.

@felixcheruiyot
Copy link
Author

Yes that will help. It might take someone quite some time to figure out such an error.

@jenssegers
Copy link
Contributor

I modified the Connection class, it should allow usernames and passwords with strange characters now.

@felixcheruiyot
Copy link
Author

Awesome. Works well now.

Cheers!

alcaeus added a commit to alcaeus/laravel-mongodb that referenced this issue Aug 16, 2023
* PHPORM-35 Add various tests on Model _id

* Add assertion on expected value

* Test _id as array and object

* Remove tests for arrays and objects as identifiers when keyType is string

---------

Co-authored-by: Andreas Braun <git@alcaeus.org>
alcaeus added a commit that referenced this issue Aug 22, 2023
* PHPORM-35 Add various tests on Model _id

* Add assertion on expected value

* Test _id as array and object

* Remove tests for arrays and objects as identifiers when keyType is string

---------

Co-authored-by: Andreas Braun <git@alcaeus.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants