0
0
MongoDBquery~10 mins

$all operator for matching all elements in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A$in
B$exists
C$elemMatch
D$all
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.
2fill in blank
medium

Complete 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'
A$elemMatch
B$in
C$all
D$size
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.
3fill in blank
hard

Fix 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'
A$all
B$exists
C$elemMatch
D$in
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.
4fill in blank
hard

Fill 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'
A$all
B"advanced"
C"beginner"
D$in
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.
5fill in blank
hard

Fill 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'
A$all
B"active"
C$gt
D$in
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.