MongoDB New User-excerpt from the network

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.