Search code examples
mongodbsharding

What is to correct syntax for adding a shard to an mongo db that requires authentication


I am trying to add a shard to mongos using the sh.addShard command following this documentation here: https://docs.mongodb.com/v3.4/tutorial/add-shards-to-shard-cluster/ the example given is:

sh.addShard( "rs1/mongodb0.example.net:27018" )

However the db that I am trying to connect to requires authentication.

sh.addShard( "rs0/admin:[email protected]:27018" )

returns this the message:

"More than one ':' detected. If this is an ipv6 address, it needs to be surrounded by '[' and ']'

Running the command without the auth returns:

"errmsg" : "not authorized on admin to execute command { listDatabases: 1, nameOnly: true }"

How can I add auth credentials to the host whilst maintaining the correct syntax.


Solution

  • addShard() will not take any authentication credentials from the best of my knowledge.

    Make sure you are under the admin db use admin and make sure if auth is turned on you successfully authenticate db.auth("username", "password")

    If your cluster has keyFile authentication on, you will need top copy the keyFile to each host and make sure the user running mongod has access to it (https://docs.mongodb.com/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set/)