How does mongodb change passwords

  mongodb, question

How does mongodb change the password? There are two methods mentioned online, the first one I haven’t tried.

I tried the second method:


But it didn’t succeed. I use admin, then executed it and reported me User tank2@admin not found. I understand this, because my admin does not have this user. But use dbname, and then db.auth after the authorization of the database, then modify the password, and report error: updating user failed: not authorized. I do not have permission to report this time.

Then I use admin authorization first, then switch back to my own database, then change the password, or report to me User tank2@dbname not found. I can be sure that my database does have this user.
Otherwise, the execution of the modification command will never end, even if you lose the semicolon! .

So I really don’t understand.


If the user name is the same, it will be overwritten and the purpose of modification will be achieved.