0
0
MongoDBquery~10 mins

Array of embedded documents queries 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 array 'scores' contains an element with 'score' equal to 100.

MongoDB
db.students.find({"scores.score": [1])
Drag options to blanks, or click blank then click option'
A100
B"100"
Cscore
D{score: 100}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "100" instead of the number 100.
Trying to match the whole embedded document instead of just the score value.
2fill in blank
medium

Complete the code to find documents where the 'scores' array contains an element with 'type' equal to 'exam'.

MongoDB
db.students.find({"scores.type": [1])
Drag options to blanks, or click blank then click option'
Aexam
B"exam"
C'exam'
D{type: 'exam'}
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string value, causing a syntax error.
Using single quotes without escaping inside JSON.
3fill in blank
hard

Fix the error in the query to find documents where the 'scores' array contains an element with 'score' greater than 90.

MongoDB
db.students.find({"scores.score": [1])
Drag options to blanks, or click blank then click option'
A{ $lt: 90 }
B{ gt: 90 }
C{ $gte: 90 }
D{ $gt: 90 }
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '$' sign before 'gt'.
Using the wrong operator like '$lt' or 'gte' when 'gt' is needed.
4fill in blank
hard

Fill both blanks to find documents where the 'scores' array contains an element with 'type' equal to 'quiz' and 'score' less than 50.

MongoDB
db.students.find({"scores": { $elemMatch: {"type": [1], "score": [2] } } })
Drag options to blanks, or click blank then click option'
A"quiz"
B{ $lt: 50 }
C{ $gt: 50 }
D"exam"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string 'quiz'.
Using $gt instead of $lt for the score condition.
5fill in blank
hard

Fill all three blanks to find documents where the 'scores' array contains an element with 'type' equal to 'homework', 'score' greater than or equal to 80, and 'score' less than 100.

MongoDB
db.students.find({"scores": { $elemMatch: {"type": [1], "score": [2], "score": [3] } } })
Drag options to blanks, or click blank then click option'
A"homework"
B{ $gte: 80 }
C{ $lt: 100 }
D"quiz"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same key 'score' twice without $elemMatch (which is invalid).
Not quoting the string 'homework'.
Using wrong operators like $gt instead of $gte.