Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 32

You are working with a products collection. Each document has the following structure:



Which query correctly filters documents where:

  • The product is available,

  • The price is greater than or equal to 500,

  • The tags array includes the value "sale"?

  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

A.

This is the correct and idiomatic way to filter:

  • $gte checks the price condition.

  • { tags: { $in: ["sale"] } } checks if the array contains "sale".

  • available: true checks availability.

B.

{ tags: { $eq: "sale" } } is redundant and less idiomatic in MongoDB, as $eq is implicit. Also, $eq won't match a value inside an array, which causes this filter to fail.

C.

While this seems correct at first glance, it relies on MongoDB's behavior that matches arrays directly. Although this would work in many cases, it’s not explicit. $in is a better, more readable and predictable option.

D.

$all: ["sale"] would still match, but it is intended for matching multiple elements. It's valid, but unnecessary for matching a single value — $in is preferred and more efficient.

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