Mongodb connection authentication auth failed solution

System: centos7
mongo client: mongo2.6.12
mongo server: mongo3.6
Connection error:

2018-07-02T11:51:48.904+0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18, codeName: "AuthenticationFailed" } at src/mongo/shell/db.js:1292
exception: login failed

Reason: Due to the low version of Mongo Client, the authentication mechanism is not supported, resulting in client authentication failure.
Solutions:

sudo yum remove mongodb
sudo yum remove mongodb-server

Install Mongodb3.6 version
Refer to CentOS 7 to install MongoDB 3.6
After successful installation, according to the authentication mechanism set by the server, select scRAM-SHA-1 or MongoDB-CR, and default to SCRAM-SHA-1
Connection command:

mongo -authenticationDatabase admin -u user -p pass -host hostname -port 27017 [--authenticationMechanism SCRAM-SHA-1]


Read More: