Localhost exception doesn't seem to apply to sharded cluster

I used the following mlaunch command:

mlaunch init --sharded 3 --replicaset --nodes 3 --config 3 --auth

❯ mongo --port 27018
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27018/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“c7a76466-1270-4138-8a7c-14357a807023”) }
MongoDB server version: 4.4.0
shard01:PRIMARY> db
test
shard01:PRIMARY> use admin
switched to db admin
shard01:PRIMARY> db.createUser({
… ‘localAdmin’,
… pwd: ‘password’,
… roles: [‘root’]
… })
uncaught exception: SyntaxError: missing : after property id :
@(shell):2:12
shard01:PRIMARY> use admin
switched to db admin
shard01:PRIMARY> db.createUser({
… user: ‘localAdmin’,
… pwd: ‘password’,
… roles: [‘root’]
… })
uncaught exception: Error: couldn’t add user: command createUser requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1343:11

From the output I tried to created a user in shard01 but it didn’t work as the lesson said.

mongo --version
MongoDB shell version v4.4.0
Build Info: {
“version”: “4.4.0”,
“gitVersion”: “563487e100c4215e2dce98d0af2a6a5a2d67c5cf”,
“modules”: ,
“allocator”: “system”,
“environment”: {
“distarch”: “x86_64”,
“target_arch”: “x86_64”
}
}

This is my mongo version

It should work on clusters also
Is the user creation run on the same host/port where rs.initiater() run?
Was there any change in the role of node like step down,new election
or may be the first attempt got exhausted(you will have only one attempt to create user with localhost exception)

I am not sure as I just ran mlaunch to do all the work, but I can retry it.

Hi @Jean-Marcel_Belmont,

You can refer to this mlaunch documentation:

Please feel free to reach out if you have any questions.

Thanks,
Sonali