I have a Sharded Cluster and I am trying to access a specific member of a replica set within a shard.
When connecting to the mongos it is fine, but when using the same credentials on a member of the replica set I am unable to gain access even though my user has the role of root.
The error is:
SCRAM-SHA-1 authentication failed for root on admin from client
127.0.0.1:39356 ; UserNotFound: Could not find user root@admin
The mongos are started with:
mongos --configdb cfg/mongo-cfg0:27019,mongo-cfg1:27019,mongo-cfg2:27019 --bind_ip_all --keyFile "/etc/mongodb-keyfile"
The members of the replica set are started with:
mongod --auth --bind_ip_all --shardsvr --replSet a --smallfiles --oplogSize 50 --keyFile "/etc/mongodb-keyfile"
When connecting to the mongos I use the following locally:
mongo --port 27017 -u user -p password --authenticationDatabase admin
When connecting to the memnber of the replica set locally i try and use:
mongo --port 27018 -u user -p password --authenticationDatabase admin
I feel like there is something obvious that I am missing but I can not figure out what, any help would be greatly appreciated.
Best Answer
When you are using
mongoS
authentication is done against config serversadmin
database. When you connect directly to replica set, you are authenticating against replica set'sadmin
database, where you don't have thatroot
user set.What can you do? Start replica set's (one by one) without --auth parameter (or equivalent config parameter) to maintenance mode, connect that RS with mongo command, create that
root
user (and other needed users). After that you can restart RS with authentication and you can do login.