title: mongodb no role named restore
body: <p>I am trying to create a user with restore privilege so that I can restore locally a database I backed up on a remote server using mongodump (NB the database requires authentification, but my issue is just creating a user for any new database).</p>
  
  <p>I am using mongo3.6.6 locally.</p>
  
  <p>On local machine I have tried to create a user with restore role using the following. Note I am creating a new local database and a new user for the new database.</p>
  
  <pre><code>mongo -u Admin -p authenticationDatabase admin
  
  #create a new database that will extract backup to
  use backup_data_db
  
  db.createUser[{
    user: "local_user",T
    pwd: "123",
    roles: [
      {role: "read", db: "backup_data_db"},
      {role: "restore", db: "backup_data_db"}]
  })
  </code></pre>
  
  <p>Whereupon I get the following error:</p>
  
  <pre><code>Error: couldn't add user: No role named restore@backup_data_db
  </code></pre>
  
  <p>I have tried creating a user with multiple role combinations - dbAdmin, readWrite, read, dbOwner, backup, restore. Out of these roles I consistently get 'No role named xxxx@backup_data_db' for only 'backup' and 'restore' roles. It seems there is something special about creating these roles that is different to other roles but I cannot find any documentation on how to create these other than the Mongo docs which I believe I am following.</p>
  
  <p>Note I also tried starting with admin database ie:</p>
  
  <pre><code>use admin
  </code></pre>
  
  <p>And repeated the same db.createUser code as above. And got the same error.</p>
  
  <p>What does work - creating a user with root privilege:</p>
  
  <pre><code>use admin
  
  db.createUser( {
  user: "rootuser",
  pwd: "passwd",
  roles: ["root", "userAdminAnyDatabase", "dbAdminAnyDatabase", 
  "readWriteAnyDatabase"] } )
  </code></pre>
  
  <p>The <a href="https://docs.mongodb.com/manual/reference/built-in-roles/#backup" rel="nofollow noreferrer">root</a> role has backup and restore privilege and there were no complaints from mongodb when creating this role.</p>
  
  <p>I then could run the following and restore the db OK</p>
  
  <pre><code>mongorestore -u rootuser -p passwd --authenticationDatabase admin -d backup_data_db path_to_backup_dir
  </code></pre>
  
  <p>Docs indicate restore is possible without root access, what am I doing incorrectly?</p>