当前位置:网站首页>User management summary of mongodb
User management summary of mongodb
2022-07-07 13:12:00 【cui_ yonghua】
The basic chapter ( Can solve the problem of 80% The problem of ):
MongoDB data type 、 Key concepts and shell Commonly used instructions
MongoDB Various additions to documents 、 to update 、 Delete operation summary
Advanced :
Other :
One . mongodb user
1.1 User management interface
To add users , You can use MongoDB Provided db.createUser() Method . When adding users , Users can be assigned roles to grant permissions .
Be careful : The first user created in the database should be a user administrator with the authority to manage other users .
You can also update existing users , For example, changing passwords and granting or revoking roles .
1.2 Verify database
When adding users , You can create users in a specific database . The database is the database of user authentication .
Users can have permissions across different databases ; That is, the user's authority is not limited to the authentication database . By assigning user roles to other databases , Users created in one database can have operation permissions on other databases .
The user name and authentication database are used as the unique identifier of the user . in other words , If two users have the same name , But create... In a different database , They are two different users . If you plan to have a single user with multiple database permissions , Create a single user with a role in the applicable database , Instead of creating users multiple times in different databases .
1.3 Authenticated user
To authenticate users , You can also connect to mongod or mongos Use the command line authentication option when instantiating ( for example :-u,-p,–authenticationDatabase) First connect to mongod or mongos example , Then run against the authentication database authenticate Order or db.auth() Method .
To authenticate , The client must authenticate the user's authentication database .
for example , If you use mongo shell As a client , You can use –authenticationDatabase Option to specify the authentication database for the user .
Two 、 Configure account and password
2.1 Open authentication
MongoDB After the default installation , Only local connections are allowed , At the same time, you can connect directly without using any account and password MongoDB, In this way, it is easy to be hacked , Let's pay some bitcoin , So in order to avoid these unnecessary troubles , So we need to give Mongo Set an account password ;
2.2 Create administrator user
> use admin
switched to db admin
> db.createUser({
user:"admin",pwd:"password",roles:["root"]})
Successfully added user: {
"user" : "admin", "roles" : [ "root" ] }
2.3 Authentication login
> db.auth("admin", "password")
2.4 MongoDB role type
Database user role (Database User Roles)
read
: grant User Access to read-only data
readWrite
: grant User Access to read and write data
Database management role (Database Administration Roles):
dbAdmin
: At present dB To perform management operations
dbOwner
: At present DB Arbitrary operation in
userAdmin
: At present DB In the management User
Backup and restore roles (Backup and Restoration Roles):
backup
restore
Cross library roles (All-Database Roles):
readAnyDatabase
: Grant permission to read data on all databases
readWriteAnyDatabase
: Grant permission to read and write data on all databases
userAdminAnyDatabase
: Grant administration on all databases User Authority
dbAdminAnyDatabase
: Grant permission to manage all databases
The role of cluster management (Cluster Administration Roles):
clusterAdmin
: Grant the highest authority to manage the cluster
clusterManager
: Grant authority to manage and monitor clusters ,A user with this role can access the config and local databases, which are used in sharding and replication, respectively.
clusterMonitor
: Grant monitoring cluster permission , The monitoring tool has readonly Authority
hostManager
: management Server
2.5 Add database users
> use flowpp
switched to db flowpp
> db.createUser({
user: "flowpp", pwd: "flopww", roles: [{
role: "dbOwner", db: "flowpp" }]}) # Create user flowpp, Set the password flopww, Set up characters dbOwner
2.6 View system users
> use admin
switched to db admin
> db.system.users.find() # Display the current system user
{
"_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : {
"SCRAM-SHA-1" : {
"iterationCount" : 10000, "salt" : "9jXmylyRAK22TZmzv1Thig==", "storedKey" : "z76cVrBjX/CTFmn5RujtU+dz7Nw=", "serverKey" : "JQGonM84iDMI1nIXW7FdyOE55ig=" } }, "roles" : [ {
"role" : "root", "db" : "admin" } ] }
{
"_id" : "flowpp.flowpp", "user" : "flowpp", "db" : "flowpp", "credentials" : {
"SCRAM-SHA-1" : {
"iterationCount" : 10000, "salt" : "KvocqWZA9E2tXBHpKpdAeQ==", "storedKey" : "50Kxc3LEgCSVN1z16S8g4A6jVp8=", "serverKey" : "0RSnsxd/7Yzmqro/YOHf/kfbHCk=" } }, "roles" : [ {
"role" : "dbOwner", "db" : "flowpp" } ] }
2.7 Delete user
# When deleting a user, you need to switch to the database managed by the user before deleting ;
1. Switch admin , Delete user flowpp , Delete failed > use admin
switched to db admin
> db.dropUser("flowpp")
false2. Switch flowpp , Delete user flowpp, Delete successful
> use flowpp
switched to db flowpp
> db.dropUser("flowpp")
true
边栏推荐
- 人均瑞数系列,瑞数 4 代 JS 逆向分析
- 环境配置篇
- Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
- Ip2long and long2ip analysis
- 企业级自定义表单引擎解决方案(十二)--体验代码目录结构
- [learning notes] zkw segment tree
- Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
- 【无标题】
- 为租客提供帮助
- MongoDB的导入导出、备份恢复总结
猜你喜欢
How to continue after handling chain interruption / sub chain error removed from scheduling
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
Awk of three swordsmen in text processing
leecode3. 无重复字符的最长子串
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
PAcP learning note 1: programming with pcap
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
分布式事务解决方案
通过Keil如何查看MCU的RAM与ROM使用情况
【无标题】
随机推荐
PACP学习笔记一:使用 PCAP 编程
Common text processing tools
JNA learning notes 1: Concepts
测试下摘要
About how appium closes apps (resolved)
How does MySQL create, delete, and view indexes?
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
工具箱之 IKVM.NET 项目新进展
Vscode编辑器ESP32头文件波浪线不跳转彻底解决
Layer pop-up layer closing problem
简单好用的代码规范
《开源圆桌派》第十一期“冰与火之歌”——如何平衡开源与安全间的天然矛盾?
TPG x AIDU|AI领军人才招募计划进行中!
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
leecode3. 无重复字符的最长子串
初学XML
Grep of three swordsmen in text processing
【无标题】
日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则