replaceOne() replaces the matched document ' s content with the replacement document, except that the immutable _id value is preserved when it is not explicitly changed. Ordinary application fields that are omitted from the replacement disappear. The required final document must retain userid, retain first, and change roles to " SuperUser " . Option B supplies all three fields and therefore produces the requested document structure. Option A omits userid, so that ordinary field would be removed from the replacement. Option C omits both userid and first, leaving only roles in addition to the preserved _id. Option D incorrectly uses the update operator $set inside a replacement document. $set belongs with update operations such as updateOne() or updateMany(); a replaceOne() replacement must be a replacement document rather than an update-operator document. This distinction is important for DBAs and application developers because accidental use of a partial replacement can delete fields that were intended to remain. If the goal is only to change one field, updateOne({userid:1}, {$set:{roles: " SuperUser " }}) would normally be safer. Given the choices, B is correct.
Study Guide reference/topic:MongoDB Architecture and Core Operations - replaceOne(), full-document replacement, and update-versus-replacement semantics.
===========
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit