mongo-php-driver icon indicating copy to clipboard operation
mongo-php-driver copied to clipboard

Mongodb authentication failed in php7

Open karsa87 opened this issue 9 years ago • 2 comments

Hy anyone,

I create new connection to mongodb from php7 but I get error : "authectication fail"

this script create new connection :

$conn = new Client("mongodb://user:password@host:port"); $db = $conn->selectDatabase("DATABASE_NAME"); $collection = $db->selectCollection("COLLECTION_NAME"); $data = $collection->find();

Is there a solution to my problem ? Is there anybody who can help me ?

We can discuss via email, this my email [email protected]

Thank you,

karsa87 avatar May 04 '17 07:05 karsa87

A few things to check would be:

  • If the username or password contains special characters (e.g. something other than alpha-numeric characters), you should encode each string with rawurlencode() as discussed in the MongoDB\Driver\Manager::__construct() and MongoDB\Client::__construct() documentation. Alternatively, you can specify the username and password in the URI options array (second parameter) in lieu of the URI string, which will not require any encoding.
  • Since you are not specifying an authentication source, the driver defaults to authenticating against the "admin" database. Depending how the user is configured, you may need to specify a difference database via the authSource URI option.
  • By default, the authMechanism defaults to SCRAM-SHA-1 for MongoDB 3.0+ and MONGODB-CR for earlier versions. Ensure that this is consistent with your database configuration.

Lastly, I'd suggest attempting to authenticate with identical options and credentials via the mongo shell to rule out any issues with the PHP driver.

jmikola avatar May 04 '17 14:05 jmikola

Closing this out due to inactivity. Feel free to followup if the issue persists.

jmikola avatar Feb 20 '18 17:02 jmikola