C100DBA · Question #106
To add a new user and enable authentication in MongoDB, which of the following steps need be executed?
The correct answer is C. update users collection and restart mongodb with -auth option. Option C is correct because MongoDB's security model requires two steps: first, creating the user by updating the users collection (via db.createUser()), and then restarting MongoDB with the --auth flag to enforce authentication on connections. Without the --auth startup option,
Question
To add a new user and enable authentication in MongoDB, which of the following steps need be executed?
Options
- Aupdate users collection and restart mongodb
- BAll of the above
- Cupdate users collection and restart mongodb with -auth option
- Dupdate users collection and run db.enableAuthenticationQ
How the community answered
(18 responses)- A6% (1)
- B6% (1)
- C89% (16)
Explanation
Option C is correct because MongoDB's security model requires two steps: first, creating the user by updating the users collection (via db.createUser()), and then restarting MongoDB with the --auth flag to enforce authentication on connections. Without the --auth startup option, MongoDB runs in open mode and ignores credentials entirely.
Why the distractors fail:
- A - Restarting without
--authleaves authentication disabled; MongoDB simply ignores the users you created. - D -
db.enableAuthentication()is not a real MongoDB command; authentication is a server-level setting controlled at startup, not from the shell. - B - "All of the above" is wrong because A and D are both incorrect methods.
Memory tip: Think of it as a two-lock system - you must set the lock (create the user) and turn the key (start with --auth). Either step alone leaves the door open.
Topics
Community Discussion
No community discussion yet for this question.