PHP Connection MongoDB user authentication error

Source: Internet
Author: User
Tags auth mongodb php mongodb
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.