Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 1

Suppose you have a companies collection in your database. Only the following documents are stored in this collection:



How many documents will be returned in response to the following aggregation pipeline?



  • A

    2

  • B

    3

  • C

    0

  • D

    4

Reveal correct answer

Correct answer: B

A.

The pipeline is designed to return the top 3 groups, not just 2. Even if two groups had the same number of companies, the $limit stage would still return 3 documents, so the correct answer is 3, not 2.

B.

The $group stage groups documents by category_code, resulting in four groups: 'search', 'advertising', 'games_video', and 'web'. The $sort stage then orders these groups by number_of_companies in descending order. Finally, the $limit stage restricts the output to the top 3 groups, meaning 3 documents are returned.

C.

The aggregation pipeline does produce results. Specifically, it returns the top 3 groups based on the number of companies, so the correct answer is not 0.

D.

Although there are four unique category_code values, the $limit stage ensures that only the top 3 groups are returned, not 4.

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