Which of the following commands will successfully create the user "dsj" and give the user read-only access to all the collections in the "nasa" database? Check all that apply:
题目选项
- A.> use admin > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa"}] })
- B.> use admin > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa", "col": "*"}] })
- C.> use nasa > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa"}] })
答案置信度:中
正确答案:A、C
解析语言:中文
A 中角色文档里的 col 不是合法字段(合法字段只有 role 和 db,要让角色覆盖某库所有集合只需写 {role:"read", db:"nasa"}),所以 A 会报错。B 在 admin 库创建用户并授予 nasa 的 read 角色可行;C 在 nasa 库创建用户并授予本库 read 角色同样可行,只是该用户需以 nasa 作为认证库,因此两项都满足题意。