How to allow creation and deletion of a database or collections with user and password

I created a user with the role of userAdminAnyDatabase

db.createUser({user: "Username", pwd: "password", roles: [{role: "userAdminAnyDatabase", db: "admin"}]})

and also user with the role of userAdmin for a single db in the mongo shell.

db.createUser({user: "Username", pwd: "password", roles: [{role: "userAdmin", db: "myDB"}]})

But when I create or delete collections in myDB it’s not asking me for the user name or password. What is the point of creating a user then?

I want the creation and deletion of databases and collections only when I give in the admin credentials.

Database Administrators Asked by DragonBorn on December 27, 2020

1 Answers

One Answer

No, system don't work that way. You must enable authentication and authorization of your mongodb.

After that, you log in with userAdmin credentials and you (only) have authorization to do userAdmin work, not system admin work. But remember to create super-admin user (before enabling authenticaton) or you end up to situation that you don't have superuser (root) who can give other needed rights.

Answered by JJussi on December 27, 2020

Add your own answers!

Related Questions

How to insert several csv files into Elasticsearch?

1  Asked on December 19, 2020 by revolucion-for-monica


passing variable values to procedure in postgresql via psql

1  Asked on December 19, 2020 by aditya-bhardwaj


PostgreSQL: interpolate missing value

1  Asked on December 17, 2020 by captainahab


duplicate key error index MongoDB

1  Asked on December 16, 2020 by simonell


Why is Postgres service failing?

1  Asked on December 13, 2020 by mike_butak


MySQL Shell dump utility – maximum possible chunk size?

1  Asked on December 10, 2020 by mihir-rane


Ask a Question

Get help from others!

© 2022 All rights reserved.