Mongodb – Can’t auth admin db on the replica set

mongodbmongodb-3.0replication

have one problem with a replica set

There is an admin user with root permissions
It's fully working on config servers, but when I trying to auth with it on any RS – got:

2017-09-18T09:01:53.755-0400 E QUERY    Error: 18 Authentication failed.
at DB._authOrThrow (src/mongo/shell/db.js:1271:32)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/db.js:1271
exception: login failed

User was added on config servers, after all Replica Set was deployed, maybe that is the problem?

Best Answer

Yes. When you "try" to authenticate directly to any replica set at the cluster, "local" admin database is used (admin database at the replica set).

You need to create that admin user locally. IF there are NO users inserted to your RS's admin database, "localhost exception" is still valid and you should not have any problem login without authentication (no -u and -p parameters on mongo -command) and create that admin user. After first user is created to RS, localhost exception is gone and you need authenticate. So, first created user MUST be admin with root rights.