A. Incorrect order of $regex arguments; 'input' must come first
B. Missing $match stage before $project
C. Using $regex instead of $regexMatch inside $filter condition
D. Cannot use $objectToArray on $ROOT
Solution
Step 1: Check $regex usage inside $filter cond
$regex is a query operator, but inside aggregation expressions, $regexMatch must be used for regex matching.
Step 2: Identify correct regex function for aggregation
Use $regexMatch with 'input' and 'regex' keys; $regex alone is invalid here.
Final Answer:
Using $regex instead of $regexMatch inside $filter condition -> Option C
Quick Check:
Aggregation regex = $regexMatch, not $regex [OK]
Hint: Use $regexMatch, not $regex, inside aggregation expressions [OK]
Common Mistakes:
Swapping input and regex keys in $regexMatch
Trying to use $regex query operator inside aggregation
Assuming $objectToArray can't be used on $ROOT
5. You have documents with variable field names like "score_math", "score_science", "age", "name". How do you write an aggregation pipeline stage to create a new field "scores" containing only fields whose names start with "score_" and their values?