Question

Cant Secure MongoDb need help

I’m trying to secure mongodb by following the link

https://www.digitalocean.com/community/tutorials/how-to-secure-mongodb-on-ubuntu-20-04

But it isn’t working. -I’m on step 1:.

This is what happens

db.createUser(
... {
... user: "Adam",
... pwd: passwordPrompt(),
... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... }
... )
Enter password:
uncaught exception: Error: couldn't add user: Could not find role: readWriteAnyD atabase@test :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1367:11
@(shell):1:1


What went wrong?

Does this mean the mongodb installation is broken? I followed the digital ocean link https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-20-04


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Rajkishore J
DigitalOcean Employee
DigitalOcean Employee badge
November 29, 2022

Hi,

This does not mean that MongoDB is broken. I have run the same command and it was successful.

db.createUser(
... ... {
... ... user: "AdminSammy",
... ... pwd: passwordPrompt(),
... ... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... ... }
... ... )
Enter password: 
Successfully added user: {
	"user" : "AdminSammy",
	"roles" : [
		{
			"role" : "userAdminAnyDatabase",
			"db" : "admin"
		},
		"readWriteAnyDatabase"
	]
}

I would suggest you to try creating use with a single role.

role: "userAdminAnyDatabase", db: "admin"

Regards, Rajkishore

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up