D. The roles field should be an array, not a string
Solution
Step 1: Check roles field format
The roles field must be an array of strings, not a single string.
Step 2: Identify error cause
Passing roles as 'read' (string) causes syntax error; it should be ['read'].
Final Answer:
The roles field should be an array, not a string -> Option D
Quick Check:
Roles must be an array like ['read'] [OK]
Hint: Roles always go inside square brackets [OK]
Common Mistakes:
Using a string instead of an array for roles
Assuming weak password causes syntax error
Using deprecated db.addUser method
5. You want to secure your MongoDB database by limiting access only to users with strong passwords and specific roles. Which combination of steps is best practice?
hard
A. Use weak passwords but restrict IP addresses only
B. Allow anonymous access but monitor logs regularly
C. Create users with strong passwords, assign roles carefully, and enable authentication
D. Disable authentication to improve performance
Solution
Step 1: Identify security best practices
Strong passwords, role-based access, and enabling authentication are key to securing MongoDB.
Step 2: Evaluate options against best practices
Create users with strong passwords, assign roles carefully, and enable authentication includes all these steps; others weaken security or disable important features.
Final Answer:
Create users with strong passwords, assign roles carefully, and enable authentication -> Option C