0
0
MongoDBquery~10 mins

Arrays in documents 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 the value 'mongodb'.

MongoDB
db.collection.find({ tags: [1] })
Drag options to blanks, or click blank then click option'
A"mongodb"
B{ "$in": ["mongodb"] }
C{ "$all": ["mongodb"] }
D{ "$elemMatch": { "$eq": "mongodb" } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in or $all unnecessarily when a direct value works.
Using incorrect query operators that don't match the array content.
2fill in blank
medium

Complete the code to find documents where the 'scores' array contains at least one value greater than 80.

MongoDB
db.collection.find({ scores: { [1]: 80 } })
Drag options to blanks, or click blank then click option'
A$gt
B$lt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means 'less than' instead of 'greater than'.
Using $eq which checks for equality, not greater than.
3fill in blank
hard

Fix the error in the query to find documents where the 'comments' array contains an object with 'author' equal to 'Alice'.

MongoDB
db.collection.find({ comments: { [1]: { author: "Alice" } } })
Drag options to blanks, or click blank then click option'
A$size
B$in
C$all
D$elemMatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in which matches values but not objects by fields.
Using $all which requires all conditions to be met by array elements.
4fill in blank
hard

Fill both blanks to find documents where the 'ratings' array has exactly 3 elements and contains the value 5.

MongoDB
db.collection.find({ ratings: { [1]: 3, [2]: [5] } })
Drag options to blanks, or click blank then click option'
A$size
B$eq
C$in
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $eq instead of $in to check for value presence in array.
Using $gt which checks for greater than, not array length.
5fill in blank
hard

Fill all three blanks to create a query that finds documents where the 'reviews' array contains an object with 'score' greater than 7 and 'verified' equal to true.

MongoDB
db.collection.find({ reviews: { [1]: { score: { [2]: 7 }, verified: { [3]: true } } } })
Drag options to blanks, or click blank then click option'
A$elemMatch
B$gt
Cverified
D$eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'verified' as a key inside $elemMatch without $eq operator.
Using $in or $all instead of $elemMatch for object matching.