title: How do you change MongoDB user permissions?
body: <p>For instance, if I have this user:</p>
  
  <pre><code>&gt; db.system.users.find()
  { "user" : "testAdmin", "pwd" : "[some hash]", "roles" : [ "clusterAdmin" ], "otherDBRoles" : { "TestDB" : [ "readWrite" ]  } }
  </code></pre>
  
  <p>And I want to give that user the <code>dbAdmin</code> permissions on the <code>TestDB</code> database, I can remove the user record then add it back with the new permissions:</p>
  
  <pre><code>&gt; db.system.users.remove({"user":"testAdmin"})
  &gt; db.addUser( { user: "testAdmin",
                    pwd: "[whatever]",
                    roles: [ "clusterAdmin" ],
                    otherDBRoles: { TestDB: [ "readWrite", "dbAdmin" ] } } )
  </code></pre>
  
  <p>But that seems hacky and error-prone.</p>
  
  <p>And I can update the table record itself:</p>
  
  <pre><code>&gt; db.system.users.update({"user":"testAdmin"}, {$set:{ otherDBRoles: { TestDB: [ "readWrite", "dbAdmin" ] }}})
  </code></pre>
  
  <p>But I'm not sure if that really creates the correct permissions - it looks fine but it may be subtly wrong.</p>
  
  <p>Is there a better way to do this?</p>