0
0
MongoDBquery~10 mins

Combining logical and comparison operators 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 age is greater than 25.

MongoDB
db.collection.find({ age: { $[1]: 25 } })
Drag options to blanks, or click blank then click option'
Alt
Beq
Cne
Dgt
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 status is 'active' and score is at least 80.

MongoDB
db.collection.find({ $and: [ { status: '[1]' }, { score: { $gte: 80 } } ] })
Drag options to blanks, or click blank then click option'
Aactive
Binactive
Cpending
Dclosed
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inactive' will find the wrong documents.
Leaving the status value empty will cause an error.
3fill in blank
hard

Fix the error in the query to find documents where age is less than 30 or score is greater than 90.

MongoDB
db.collection.find({ $or: [ { age: { $[1]: 30 } }, { score: { $gt: 90 } } ] })
Drag options to blanks, or click blank then click option'
Alte
Beq
Clt
Dgte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gte will find ages greater than or equal to 30, which is wrong here.
Using $eq will only find age exactly 30.
4fill in blank
hard

Fill both blanks to find documents where status is 'pending' and age is not equal to 40.

MongoDB
db.collection.find({ $and: [ { status: '[1]' }, { age: { $[2]: 40 } } ] })
Drag options to blanks, or click blank then click option'
Apending
Bactive
Cne
Deq
Attempts:
3 left
💡 Hint
Common Mistakes
Using $eq instead of $ne will find age exactly 40, not excluding it.
Using wrong status value will find wrong documents.
5fill in blank
hard

Fill all three blanks to find documents where name starts with 'J', age is greater than 20, and score is less than or equal to 100.

MongoDB
db.collection.find({ $and: [ { name: { $regex: '^[1]' } }, { age: { $[2]: 20 } }, { score: { $[3]: 100 } } ] })
Drag options to blanks, or click blank then click option'
AJ
Bgt
Clte
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt for age will find wrong documents.
Using $lt instead of $lte for score excludes 100.