mongoDB -- 用户
2021/4/15 19:55:13
本文主要是介绍mongoDB -- 用户,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 db.createUser(user, writeConcern)
db.createUser(user, writeConcern)
为运行该方法的数据库创建新用户。如果用户已经存在于数据库中,则返回一个重复用户错误
Field | Type | Type |
---|---|---|
user | document | 要创建的用户的身份验证和访问信息 |
writeConcern | document | 可选,创建操作的写关注级别。writeConcern文档接受与getLastError命令相同的字段 |
user 文档参数
{ user: "<name>", pwd: passwordPrompt(), // Or "<cleartext password>" customData: { <any information> }, roles: [ { role: "<role>", db: "<database>" } | "<role>", ... ], authenticationRestrictions: [ { clientSource: ["<IP>" | "<CIDR range>", ...], serverAddress: ["<IP>" | "<CIDR range>", ...] }, ... ], mechanisms: [ "<SCRAM-SHA-1|SCRAM-SHA-256>", ... ], passwordDigestor: "<server|client>" }
Field | Type | Description |
---|---|---|
user | string | 新用户的名字 |
pwd | string | 用户密码。可以是明确的密码字符串,可以是 passwordPrompt()方法,提示输入用户密码。 |
customData | document | 可选,任意信息。此字段可用于存储管理员希望与此特定用户关联的任何数据。例如,这可以是用户的全名或员工id |
roles | array | 授予用户的角色。可以指定空数组[]来创建没有角色的用户 |
authenticationRestrictions | array | 可选, 服务器对创建的用户实施的身份验证限制。指定一个IP地址列表和CIDR范围,允许用户连接到服务器,或者服务器可以接受用户 |
mechanisms | array | 可选,指定特定SCRAM机制 或 创建SCRAM用户凭据的机制。 只能是 "SCRAM-SHA-1" "SCRAM-SHA-256" |
passwordDigestor | string | 可选,表示服务器还是客户端接收密码。可选值:"server" (默认) , "client" (与 SCRAM-SHA-256 不兼容 ) |
authenticationRestrictions
| Field | Type | Description |
| ---- | ---- | ---- |
| clientSource | IP地址和/或CIDR范围的数组 | 如果存在,当对用户进行身份验证时,服务器验证客户端的IP地址是否在给定的列表中或属于列表中的CIDR范围。如果客户机的IP地址不存在,服务器就不会对用户进行身份验证。|
| serverAddress | IP地址和/或CIDR范围的数组 | 客户端可以连接到的IP地址或CIDR范围的列表。如果存在,服务器将通过给定列表中的IP地址验证客户端连接是否被接受。如果连接通过一个无法识别的IP地址被接受,服务器就不会对用户进行身份验证。 |
从4.0.9版开始,MongoDB在创建用户时自动分配一个唯一的用户id
如果在复制集中运行,db.createUser()默认使用majority write concern执行
不能在 local 数据库上创建用户
这篇关于mongoDB -- 用户的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-01got an unexpected keyword argument
- 2024-03-30维多利亚的秘密 golang入坑系统
- 2024-03-29mongodb sort by date
- 2024-03-29go swagger
- 2024-03-25mongodb cdc
- 2024-03-25how to use go in vscode
- 2024-03-22mongooseserverselectionerror: connect econnrefused ::1:27017
- 2024-03-21pymongo insert_many
- 2024-03-18projection mongodb
- 2024-03-14clickhouse-go