Which query would you use to return all customers with a satisfaction rating of 1 or 2?

Prepare for the MongoDB Associate Developer Exam with flashcards and practice multiple choice questions. Each question includes hints and explanations to ensure you're ready for test day.

To retrieve all customers with a satisfaction rating of 1 or 2, the correct query uses a combination of conditions that effectively capture both ratings. The choice that accomplishes this does so by specifying that the satisfaction rating must be less than or equal to 2, while still implicitly allowing for ratings lower than that, which must include the value of 1.

The core concept here lies in understanding how comparison operators work within MongoDB. The operator used in the correct choice, $lte (less than or equal to), allows the query to return any document where the satisfaction rating is either 1 (satisfactory) or 2 (still satisfactory but lower), thus fulfilling the requirement to capture both scenarios.

The other query options would not meet the requirement for the following reasons:

  • Using $gte with 1 would return any rating of 1 and above, including ratings higher than 2, which is outside the desired range.

  • $gte with 2 would exclude any rating below 2, thereby missing the customers rated with a 1.

  • Using $eq with 1 would return only those customers rated exactly 1, omitting any customers rated with a 2.

Thus, the enabled range catered by the correct choice ensures that all

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy