Reputation: 177
I'm fighting to get my MongoDB container to work with authentication.
I created a database, and a user on that database with the dbAdmin role. But it seems this role is not enough to be able to insert data to the database, because when I run a script which populates my DB, I get this kind of error message:
error: not authorized on mydb to execute command { insert: "attachs", documents: 59, writeConcern: { getLastError: 1, w: 1 }, ordered: false }
So I guess I need to add some other privileges for my user, but I can't figure out which are missing.
Upvotes: 0
Views: 1722
Reputation: 646
To add to the above answer, for an existing user, you can use the db.grantRolesToUser() command to assign it readWrite role. E.g.
use test
db.grantRolesToUser("user1", [ "readWrite"] )
Above grants user1 the readWrite role on the test database. I wrote a step by step tutorial on how to grant privileges to roles and roles to users recently. It might be useful.
Upvotes: 0
Reputation: 15854
db.createUser({
user : "root",
pwd : "root",
roles : ["readWrite", "dbAdmin"]
});
You can create a role with readWrite. It will work.
Upvotes: 1