In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
MongoDB management user authentication mechanism is what, I believe many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
MongoDB user authentication mechanism
To authenticate clients, you must add a corresponding user to MongoDB. The basic steps are as follows:
User management interface: db.createUser() method can create a user, after adding can assign roles to users, the first user must be an administrator, used to manage other users. You can also update existing users, and you must change passwords and permissions.
Authentication database: When you add a user, you add that user to a specified database, and that database is an authentication database for that user. A user can have access to multiple databases by assigning role permissions.
Authenticate the user: To authenticate the user, you can use the db.author() method.
MongoDB user authentication example
In the admin database, create a superuser to manage other users.
use admindb.createUser({"user":"myadmin","pwd":"password","roles":["root"]})
Log in to the database again, execute: show dbs, and find that it can still be accessed. We need to turn on the authentication mechanism of the database and set the following parameters in the configuration file:
auth=true
Restart MongoDB and log back in.
Execution: show dbs, error occurred
Perform authentication user, perform show users View user information
use admindb.auth("myadmin","password")show users
Show DBs is executed normally.
Create a new user in mydemo database
use mydemodb.createUser({"user":"user1","pwd":"password","roles":["read"]}) Note: This user has only read roles
Do the following to test.
Switch user: db.auth("user1","password") Query collection: db.emp.findOne() --> Can operate normally Insert new document: db.testtable2.insert({"name","Tom"}) ---> Error
Change user password
db.updateUser("user1",{"pwd":"abcd"})
View users: show users
After reading the above, do you know how MongoDB manages user authentication? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.