0
0
MongoDBquery~10 mins

Why logical operators matter 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$lt
B$gt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt will find ages less than 25, which is wrong here.
Using $eq looks for exactly 25, not greater than 25.
2fill in blank
medium

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

MongoDB
db.orders.find({ [1]: [ { status: 'A' }, { status: 'B' } ] })
Drag options to blanks, or click blank then click option'
A$or
B$not
C$and
D$nor
Attempts:
3 left
💡 Hint
Common Mistakes
Using $and requires both conditions to be true, which is too strict here.
Using $not negates a condition, which is not what we want.
3fill in blank
hard

Fix the error in the query to find documents where age is greater than 20 and less than 30.

MongoDB
db.people.find({ [1]: [ { age: { $gt: 20 } }, { age: { $lt: 30 } } ] })
Drag options to blanks, or click blank then click option'
A$not
B$or
C$nor
D$and
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or would find ages greater than 20 or less than 30, which is too broad.
Using $not or $nor changes the meaning to exclude conditions.
4fill in blank
hard

Fill both blanks to find documents where score is greater than 80 and status is 'active'.

MongoDB
db.results.find({ [1]: [ { score: { $gt: 80 } }, { status: [2] } ] })
Drag options to blanks, or click blank then click option'
A$and
B'active'
C'inactive'
D$or
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or would allow either condition, not both.
Using 'inactive' for status would find wrong documents.
5fill in blank
hard

Fill all three blanks to find documents where age is between 18 and 25 inclusive, and status is not 'inactive'.

MongoDB
db.users.find({ [1]: [ { age: { [2]: 18 } }, { age: { [3]: 25 } }, { status: { $ne: 'inactive' } } ] })
Drag options to blanks, or click blank then click option'
A$and
B$gte
C$lte
D$or
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or would allow any condition, not all.
Using $gt or $lt excludes the boundary values.