In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.