0
0
MongoDBquery~10 mins

$in for matching a set 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 field 'color' matches any value in the list.

MongoDB
db.collection.find({ color: { [1]: ["red", "blue", "green"] } })
Drag options to blanks, or click blank then click option'
A$ne
B$eq
C$in
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $eq instead of $in will only match a single value, not a list.
Using $gt or $ne will not match multiple values as intended.
2fill in blank
medium

Complete the code to find documents where the 'status' field is either 'active' or 'pending'.

MongoDB
db.users.find({ status: { [1]: ["active", "pending"] } })
Drag options to blanks, or click blank then click option'
A$nin
B$in
C$exists
D$all
Attempts:
3 left
💡 Hint
Common Mistakes
Using $nin will exclude those values instead of including them.
Using $all requires the field to contain all listed values, which is not suitable here.
3fill in blank
hard

Fix the error in the query to correctly find documents where 'category' is one of the specified values.

MongoDB
db.products.find({ category: { [1]: ["electronics", "furniture"] } })
Drag options to blanks, or click blank then click option'
A$nin
B$eq
C$all
D$in
Attempts:
3 left
💡 Hint
Common Mistakes
Using $eq with multiple values causes syntax errors.
Not using an array for multiple values with $in causes errors.
4fill in blank
hard

Fill both blanks to find documents where 'tags' contain any of the specified values.

MongoDB
db.articles.find({ tags: { [1]: ["mongodb", "database"], [2]: true } })
Drag options to blanks, or click blank then click option'
A$in
B$all
C$exists
D$nin
Attempts:
3 left
💡 Hint
Common Mistakes
Using $all instead of $in requires all values to be present, which is stricter.
Omitting $exists might include documents without the 'tags' field.
5fill in blank
hard

Fill all three blanks to find documents where 'status' is in the list and 'score' exists and is greater than 50.

MongoDB
db.records.find({ status: { [1]: ["open", "closed"] }, score: { [2]: true, [3]: 50 } })
Drag options to blanks, or click blank then click option'
A$in
B$exists
C$gt
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt will find scores less than 50.
Omitting $exists might include documents without a 'score' field.