Add user rights to the MongoDB method share _mongodb

Source: Internet
Author: User
Tags install mongodb mongodb

Using the MongoDB database, you need to add user rights to each database, check the following code:

Copy Code code as follows:

Use Test2
Db.adduser ({User: "Test")
PWD: "Admin",
roles: ["ReadWrite", "Dbadmin"]
} )

After execution found:

Copy Code code as follows:

$ MONGO 192.168.1.111/test2-u test-p Admin
Mymongo:primary>

Copy Code code as follows:

error:18 {ok:0.0, errmsg: "Auth failed", code:18} at src/mongo/shell/db.js:228

Detection version Discovery

Copy Code code as follows:

$mongo--help
MongoDB Shell version:2.4.9

The MongoDB I used was version 2.6, but the shell was 2.4.9, and it felt like there was a problem with the text, so the following scenario was used:

Delete the old version of the client

Copy Code code as follows:

sudo apt-get remove mongodb-clients
sudo apt-get autoremove
sudo apt-get AutoClean

Install a new shell

Copy Code code as follows:

sudo apt-get install mongodb-org-shell=2.6.1
$mongo--help
MongoDB Shell version:2.6.1

Add a user with a new (Mongodb 2.6 code)

Copy Code code as follows:

Use Test2
Db.createuser (
{
User: "Test",
PWD: "Admin",
Roles
[
{role: "ReadWrite", DB: "Test2"},
]
}
)

Copy Code code as follows:

$mongo 192.168.1.111/test2-u test-p Admin
Mymongo:primary>

Login successful!!!!

The above mentioned is the entire content of this article, hope to be able to understand the MONGO database to have the help.

Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!

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.