Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find documents where the 'tags' array contains all specified elements.
MongoDB
db.collection.find({ tags: { [1]: ["red", "blue"] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in instead of $all matches any one element, not all.
Using $elemMatch is for matching elements with conditions, not all elements.
Using $exists checks for field existence, not array contents.
✗ Incorrect
The $all operator matches documents where the array contains all the specified elements.
2fill in blank
mediumComplete the query to find documents where the 'colors' array contains all of 'green' and 'yellow'.
MongoDB
db.products.find({ colors: { [1]: ["green", "yellow"] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in returns documents with any one of the elements, not all.
Using $size checks array length, not contents.
Using $elemMatch is for matching elements with conditions.
✗ Incorrect
The $all operator ensures the array contains all specified elements.
3fill in blank
hardFix the error in the query to correctly find documents where 'features' contains all specified values.
MongoDB
db.items.find({ features: { [1]: ["wifi", "bluetooth"] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in matches any element, not all.
Using $elemMatch is for complex conditions, not all elements.
Using $exists checks if the field exists, not its contents.
✗ Incorrect
Only $all matches documents where the array contains all listed elements.
4fill in blank
hardFill both blanks to find documents where 'skills' array contains all specified skills and the 'level' is 'advanced'.
MongoDB
db.users.find({ skills: { [1]: ["python", "mongodb"] }, level: [2] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in instead of $all for skills.
Using wrong string for level like "beginner".
Not quoting the level string.
✗ Incorrect
Use $all to match all skills and specify the level as the string "advanced".
5fill in blank
hardFill all three blanks to find documents where 'tags' contains all specified tags, 'status' is 'active', and 'priority' is greater than 5.
MongoDB
db.tasks.find({ tags: { [1]: ["urgent", "client"] }, status: [2], priority: { [3]: 5 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in instead of $all for tags.
Not quoting the status string.
Using $lt or $lte instead of $gt for priority.
✗ Incorrect
Use $all for tags, "active" string for status, and $gt operator for priority greater than 5.