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.
db.createUser({
user : "root",
pwd : "root",
roles : ["readWrite", "dbAdmin"]
});
You can create a role with readWrite. It will work.