Report this

What is the reason for this report?

Cant Secure MongoDb need help

Posted on July 23, 2022

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



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.