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!