How to use pymongo command updateUser
<p>How do i use pymongo command updateUser ?</p>

<p>I've tried the following commands but with no success:</p>

<pre><code>db.command({'updateUser': 'my_user','update':{'$set':{"pwd":"my_pwd"}}})
</code></pre>

<p>And </p>

<pre><code>db.command('updateUser', {"updateUser":"my_user","pwd":"my_pwd"})
</code></pre>

<p>Returns</p>

<pre><code>pymongo.errors.OperationFailure: Must specify at least one field to update in updateUser
</code></pre>

<p>Thanks.</p>

<p>The python code is executing the MongoDB command "updateUser" on the database side. The command being executed in your code doesn't match the syntax shown in the <a href="https://docs.mongodb.com/manual/reference/command/updateUser/" rel="nofollow">updateUser documentation</a>.</p>

<p>Try the following: </p>

<pre><code>db.command( { updateUser: "&lt;username&gt;",
 pwd: "&lt;cleartext new password&gt;",
 roles: [
  // specify any roles assigned to this user. 
 ]
})
</code></pre>

<p>The command will completely replace the database user, so any and all role or permission information will need to be specified in the update command.</p>

python linux mongodb pymongo-3.x