There is a user in database, this user should be renamed. How to rename the user? The MongoDB user management reference has method db.updateUser but I don't see how to set a new name for the user. How to update the username? ty
db.updateUser(
"<username>",
{
customData : { <any information> },
roles : [
{ role: "<role>", db: "<database>" } | "<role>",
...
],
pwd: "<cleartext password>"
},
writeConcern: { <write concern> }
)
users. update({"user":"oldname"}, {$set:{"user":"newname"}}) gave error ( "errmsg" : "not authorized on admin to execute command { update: ) for the user with following roles roles : [ { role : "userAdminAnyDatabase", db : "admin" } ] .
You cannot update it but you can save a new id and remove the old id.
By default mongodb has no enabled access control, so there is no default user or password. To enable access control, use either the command line option --auth or security. authorization configuration file setting.
Did you try to update the user?
db.system.users.update({"user":"oldname"}, {$set:{"user":"newname"}})
This command requires root
access to admin database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With