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
2

1 Answer 1

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" } ]
  }
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.