BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

MongoDB C100DBA Exam - Topic 1 Question 134 Discussion

Posted by Justine on Sep 25, 2026 at 08:06 PM

A department store maintains a clothing collection:

{ "_id": 1, "item": "sweater", "sizes": [ "XS", "S", "L" ] }

{ "_id": 2, "item": "t-shirt", "sizes": [ "S", "M", "L" ] }

{ "_id": 3, "item": "vest", "sizes": [ "M", "L", "XL", "XXL" ] }

An employee runs:

db.clothing.find( { "sizes": "M" } )

Which index should improve performance for this query the MOST?

Suggested Answer: A

The query filters only on the sizes field, so the most direct supporting index is a single-field index on sizes. Because sizes contains arrays, MongoDB automatically treats the resulting index as a multikey index and creates index entries derived from the array elements. That allows the query { sizes: 'M' } to locate matching documents through the index rather than scanning every document in the collection. Option B indexes item, which is not part of the predicate and therefore does not help this query. Option C contains sizes, but _id is the leading key and the query provides no equality restriction on _id; this prevents efficient use of the later key as a standalone prefix for the query. Option D has the same structural problem because item precedes sizes and is not constrained. MongoDB's index-prefix rules make a targeted { sizes: 1 } index the strongest choice here. In a real workload, DBAs should also consider write overhead and whether additional queries can share a compound index before creating redundant indexes. For this single query pattern, option A is optimal.

Study Guide reference/topic:Indexing and Query Optimization - multikey indexes, array fields, index prefixes, and query support.

===========


Get Premium C100DBA Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
12 comments · newest first
RE
Refugia 4 days ago
Definitely A! Indexing sizes is key here.
AL
Aleta 9 days ago
I think D could work too, but A seems more direct.
KI
Kirby 14 days ago
Option A is the best choice for this query.
DA
Dahlia 19 days ago
Indexing sizes is definitely the way to go!
WI
Wilda 24 days ago
I think D) could work too, but not as well.
DE
Destiny 29 days ago
Wait, why not just use the _id index?
GE
Gennie 1 month ago
Totally agree, sizes index makes sense!
EL
Elza 1 month ago
A) is the best choice for that query.
DO
Doug 2 months ago
I’m a bit confused about the compound indexes. Wouldn't just indexing sizes be enough for this query?
CA
Catrice 2 months ago
I practiced a similar question, and I feel like creating an index on sizes would definitely help speed up the query.
BL
Blondell 2 months ago
I'm not entirely sure, but I remember something about compound indexes being useful. Maybe option D could be a good choice?
GL
Gladys 2 months ago
I think the index on sizes alone would be the best choice since the query specifically looks for "M" in sizes.
0/2000 characters

Save Cancel