PHP Connection MongoDB user authentication error
Main error message:
authentication failed MONGODB-CR credentials missing in the user document
MongoDB can not link MongoDB in php after –auth is enabled, prompting user authentication failure
laravel Error:
Errorexception in 29a407fb57431b351434fab7e1c79ec5 Line 5:
Failed to connect to:localhost:27017:authentication Failed in database ' Laravel ' with username ' laravel ': Auth Failed
Look at the code, is in accordance with the standard PHP manual write ah, the library is the user, the user name password is also true, but why the verification does not pass it:
$m = new Mongoclient ("Mongodb://${username}:${password} @localhost", Array ("DB" => "MyDatabase"));
To view the MONGO console, it was found that the newspaper was wrong:
Failed to authenticate laravel@laravel with mechanism mongodb-cr:authentication Failed MONGODB-CR credentials missing in The user document
There's no MONGODB-CRin the user's document, what the hell.
After some toss to find that there is no such a mistake in the domestic solution.
Helpless Google to a blog:
[https://code4foodblog.wordpress.com/2015/03/31/ Authenticationfailed-mongodb-cr-credentials-missing-in-the-user-document/] This is a way to solve
Find out the official documents on MONGO, about the MONGODB certification mechanism:
MongoDB ' s default authentication method is a challenge and response mechanism (SCRAM-SHA-1). Previously, MongoDB used MongoDB Challenge and Response (MONGODB-CR) as the default.
mongo3.0 does not use MONGO-CR as the default user authentication method, the default is scram-sha-1
Go to the Phpinfo MONGO section to see:
Supported authentication mechanisms |
- |
MONGODB-CR (default) |
Enabled |
mongodb-x509 |
Enabled |
GSSAPI (Kerberos) |
Enabled |
PLAIN |
Enabled |
There's no scram-sha-1 here.
Sure enough, the root of the PHP MongoDB driver is not updated, Khan
In [Https://pecl.php.net/package/mongo] Find the right driver, decisively passed, a little problem toss for a long time