Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 41

You are managing a MongoDB database for a fitness tracking application. The application tracks user activity through a Users collection. Each user document includes fields like name, age, height, weight, and activity logs. Here is a sample document from the Users collection:


Original Document:



You want to update John's weight and add a new activity log entry using the following update operation:



What will the final document in the database look like after this update?

  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

A.

The $set operator updates the specified fields without affecting other fields in the document. Here, the weight field is updated to 78, and the activity_logs array is updated to include the new log entry for "2024-08-03". The previous entries in the activity_logs array are retained, and the new entry is added, resulting in a complete update without data loss.

B.

This answer is incorrect because it suggests that one of the previous entries in the activity_logs array was lost. The $set operation retains all elements specified in the new array.

C.

This answer is incorrect because it fails to include the new log entry, which was part of the update operation. The correct update retains all entries specified in the new array, including the new one.

D.

This answer is incorrect because it assumes that one of the previous entries in the activity_logs array was replaced. The $set operator replaces the entire array, but the new array explicitly includes all previous entries along with the new one.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need