0
0
MongoDBquery~10 mins

Why query operators are needed in MongoDB - Test Your Understanding

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

Complete the code to find documents where age is greater than 25.

MongoDB
db.users.find({ age: { [1]: 25 } })
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 instead of $gt will find ages less than 25.
Using $eq will find ages exactly 25, not greater.
2fill in blank
medium

Complete the code to find documents where the status is either 'A' or 'B'.

MongoDB
db.orders.find({ status: { [1]: ["A", "B"] } })
Drag options to blanks, or click blank then click option'
A$and
B$in
C$or
D$nin
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or requires multiple conditions, not an array.
Using $nin finds documents NOT in the list.
3fill in blank
hard

Fix the error in the query to find documents where score is less than or equal to 80.

MongoDB
db.scores.find({ score: { [1]: 80 } })
Drag options to blanks, or click blank then click option'
A$gte
B$lt
C$lte
D$eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt finds scores strictly less than 80, excluding 80.
Using $gte finds scores greater than or equal to 80.
4fill in blank
hard

Fill both blanks to find documents where price is greater than 50 and less than 100.

MongoDB
db.products.find({ price: { [1]: 50, [2]: 100 } })
Drag options to blanks, or click blank then click option'
A$gt
B$lt
C$gte
D$lte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gte or $lte changes the range to include 50 or 100.
Swapping the operators will cause wrong results.
5fill in blank
hard

Fill all three blanks to find documents where age is at least 18, less than 65, and status is 'active'.

MongoDB
db.users.find({ age: { [1]: 18, [2]: 65 }, status: [3] })
Drag options to blanks, or click blank then click option'
A$gte
B$lt
C"active"
D"inactive"
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $gte excludes age 18.
Using $lte includes age 65, which is not wanted.
Setting status to 'inactive' returns wrong documents.