Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a user in MongoDB?

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> }
)
like image 856
Developer Marius Žilėnas Avatar asked Feb 08 '16 08:02

Developer Marius Žilėnas


People also ask

How do I change my MongoDB username?

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" } ] .

Can we rename _ID in MongoDB?

You cannot update it but you can save a new id and remove the old id.

What is my username in MongoDB?

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.


1 Answers

Did you try to update the user?

db.system.users.update({"user":"oldname"}, {$set:{"user":"newname"}})

This command requires root access to admin database.

like image 123
Alex Blex Avatar answered Oct 21 '22 03:10

Alex Blex