cswuyg
cswuyg

Reputation: 56

How to connect to mongodb authentication instance which is one member of replica shard cluster?

Why the account create from mongos, can not be use at replica instance?
the log :

[conn165] SCRAM-SHA-1 authentication failed for wuyg on admin from client 127.0.0.1 ; UserNotFound: Could not find user wuyg@admin  

the user wuyg has these roles:

"roles" : [ { "role" : "clusterAdmin", "db" : "admin" }, { "role" : "dbOwner", "db" : "admin" }, { "role" : "userAdminAnyDatabase", "db" : "admin" } ]  

and I can use the wuyg account when I connect from mongos.

My mongodb cluster has 3 config instance, and 1 shard which is a 3 members replica cluster. version:3.2.8

thanks.

Upvotes: 0

Views: 582

Answers (1)

Bartlomiej Nogas
Bartlomiej Nogas

Reputation: 340

In mongoDB users are kept in admin.system.users collections. You can list users using commands:

use admin
db.system.users.find()

Each ReplicaSet instance has it's own admin database with separate system.users collection.

Mongos(shardedCluster) use admin database which is kept on config servers.

If you want to connect to mongos and replicaSet using the same user you have to create this user on replicaSets and mongos separately

BTW It's better to use simple replicaSet configuration if you have only one shard. You can convert it to shardedCluster when you need additional capacity https://docs.mongodb.com/manual/tutorial/convert-replica-set-to-replicated-shard-cluster/.

Upvotes: 2

Related Questions