当前位置:网站首页>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
边栏推荐
- PAcP learning note 3: pcap method description
- How to reset Google browser? Google Chrome restore default settings?
- What are the benefits of ip2long?
- Grep of three swordsmen in text processing
- HZOJ #235. Recursive implementation of exponential enumeration
- 日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
- 分屏bug 小记
- TPG x AIDU|AI领军人才招募计划进行中!
- Initialization script
- How to reset Firefox browser
猜你喜欢
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
《ASP.NET Core 6框架揭秘》样章[200页/5章]
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
自定义线程池拒绝策略
MongoDB内部的存储原理
认养一头牛冲刺A股:拟募资18.5亿 徐晓波持股近40%
Go language learning notes - structure
Adopt a cow to sprint A shares: it plans to raise 1.85 billion yuan, and Xu Xiaobo holds nearly 40%
[Presto profile series] timeline use
随机推荐
MongoDB内部的存储原理
[untitled]
将数学公式在el-table里面展示出来
regular expression
Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
抓细抓实抓好安全生产各项工作 全力确保人民群众生命财产安全
How does MySQL create, delete, and view indexes?
JS determines whether an object is empty
存储过程的介绍与基本使用
JS中为什么基础数据类型可以调用方法
Sequoia China completed the new phase of $9billion fund raising
[untitled]
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
Pcap learning notes II: pcap4j source code Notes
Find ID value MySQL in string
.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
Cinnamon Applet 入门
Go语言学习笔记-结构体(Struct)
Cmu15445 (fall 2019) project 2 - hash table details
JS判断一个对象是否为空