MongoDB DBA · Question 398 · Multiple choice

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:

Answer options

  1. A.
    > use admin > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa"}] })
  2. B.
    > use admin > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa", "col": "*"}] })
  3. C.
    > use nasa > db.createUser({ "user":"dsj", "pwd": "explorer", "roles": [{"role": "read", "db": "nasa"}] })

Answer confidence: Medium

Correct answer: A, C

Explanation language: Chinese

A 中角色文档里的 col 不是合法字段(合法字段只有 role 和 db,要让角色覆盖某库所有集合只需写 {role:"read", db:"nasa"}),所以 A 会报错。B 在 admin 库创建用户并授予 nasa 的 read 角色可行;C 在 nasa 库创建用户并授予本库 read 角色同样可行,只是该用户需以 nasa 作为认证库,因此两项都满足题意。

Papers containing this question

This question appears in 2 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗