With the version of the update, the use of MongoDB in the business also made version upgrades, but in the drop off a database, the problem came, the original user with the deletion of the library is also deleted, but again want to through the original syntax Db.adduser () added, has been error, Prompt to create with the Db.createuser () command. First, if the user except the Admin library is added through Db.adduser (), it will not succeed. I deleted the root user of the original admin library and created it by Db.createuser ():
Dbcreateuser (
{
User: "root" Pwd: "root" Roles:
[
{
Role: "useradminanydatabase" ,
db : "admin"
}
Span class= "pun" >
}
);
Switch to another library to delete the original user
Use test
DB. System. Users. Remove({user:"Test"});
Or
DB. Dropuser("test")
New user
DB. AddUser(' test ',' test123 ');
Using the older commands above will have warning, but you can still create a successful
WARNING:the' AddUser 'is DEPRECATED. please use instead
It is recommended that you create it with the following command
Db.createuser (
{
User: "Test",
PWD: "Test123",
Roles
[
{
Role: "Dbowner",
DB: "Test"
}
]
}
);
Please refer to: Db.createuser () syntax now 2.6 has the concept of role, with its own role, can also create new role as needed, to give a user, here no more detailed, see what role, use show roles can
MongoDB New User-excerpt from the network