0

I can't believe that there is no simple example for this. I keep reading different versions everywhere.

mongo --port 27017 -u "admin" -p "mypass" --authenticationDatabase "mydb"
use mydb
db.createUser(
  {
    user: "normal",
    pwd: "anotherpass",
    roles: [ { role: "readWriteAnyDatabase", db: "mydb" } ]
  }
)

I get:

Error: couldn't add user: No role named readWriteAnyDatabase
basickarl
  • 37,187
  • 64
  • 214
  • 335

1 Answers1

7

From the website:

Changed in version 3.4: Prior to 3.4, readWriteAnyDatabase includes local and config databases. To provide readWrite privileges on the local database, create a user in the admin database with readWrite role in the local database.

If you want the desired output, I believe you just have to go to the admin database use admin and create an user with the following command:

db.createUser(
  {
    user: "normal",
    pwd: "anotherpass",
    roles: [ { role: "readWrite", db: "mydb" } ]
  }
)
Israel Zinc
  • 2,713
  • 2
  • 18
  • 30