Can't create a root user from mongo shell

im in mongo shell traying to create the 1st superuser with all permissions;

use admin
switched to db admin
MongoDB Enterprise atlas-feuibs-shard-0:PRIMARY> db.createUser({user:'root', pwd:'1234', roles: ['root']})
uncaught exception: Error: couldn't add user: (Unauthorized) not authorized on admin to execute command { createUser: "root", pwd: "1234", roles: [root], digestPassword: true, writeConcern: { w: "majority", wtimeout: 600000.0 }, lsid: { id: {4 [171 148 62 18 97 202 76 208 154 77 242 106 20 185 219 71]} }, $clusterTime: { clusterTime: {1617362319 8}, signature: { hash: {0 [4 101 176 140 52 204 125 92 233 30 123 196 177 26 148 123 7 241 173 182]}, keyId: 6942616266624466944.000000 } }, $db: "admin" } :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1386:11
@(shell):1:1

I can’t access config file:

mongod -f /etc/mongod.conf
uncaught exception: ReferenceError: mongod is not defined :
@(shell):1:1
MongoDB Enterprise atlas-feuibs-shard-0:PRIMARY> db.getUser('m001-student')
{
	"_id" : "admin.m001-student",
	"user" : "m001-student",
	"db" : "admin",
	"roles" : [
		{
			"role" : "readWriteAnyDatabase",
			"db" : "admin"
		}
	]
}
MongoDB Enterprise atlas-feuibs-shard-0:PRIMARY> db.auth('m103-student')
Enter password: 
Error: Authentication failed.
0

Created another db called ‘rutas’ but no go:

use rutas
switched to db rutas

MongoDB Enterprise atlas-feuibs-shard-0:PRIMARY> db.createUser({user: 'dios', pwd: 'divine', roles: ['root']})
uncaught exception: Error: couldn't add user: CMD_NOT_ALLOWED: createUser :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1386:11
@(shell):1:1

any ideas how to solve this?
thanks !!!

You cannot manipulate users from the shell when connected to Atlas. You have to use the Atlas GUI or API.

See https://docs.atlas.mongodb.com/security-add-mongodb-users/

1 Like

excellent thanks !!!

1 Like

Hi @Leo_Aramburu,

I hope you got the solution to your problem.
If you still have any questions feel free to reach out.

Thanks
Kushagra

thanks !!!
didnt solve the problem but its ok

From the mongo shell prompt, we can see that he is connected to an Atlas cluster. There is no configuration file to share. Database users cannot be manipulated with the shell. It is not a problem. It is a security feature of Atlas.

Hi @Leo_Aramburu,

As @steevej noted, Atlas database users have to be managed via the Atlas UI or API. You cannot manage Atlas database users via the mongo shell. If you’re still having trouble creating a new user, can you provide more information on the steps you are taking and any error messages or outcomes?

Regards,
Kushagra

1 Like

Good to know thanks !!!

regards ,
Leo.

1 Like