0
0
MongoDBquery~10 mins

Combining 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 only find ages exactly 25.
2fill in blank
medium

Complete the code to find documents where age is less than or equal to 30.

MongoDB
db.collection.find({ age: { $[1]: 30 } })
Drag options to blanks, or click blank then click option'
Agte
Blte
Cgt
Dne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gte will find ages greater than or equal to 30, which is the opposite.
Using $ne will exclude age 30 but include others.
3fill in blank
hard

Fix the error in the query to find documents where age is between 20 and 40 (inclusive).

MongoDB
db.collection.find({ age: { $gte: 20, $[1]: 40 } })
Drag options to blanks, or click blank then click option'
Agt
Bne
Clte
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt excludes 40 from results.
Using $gt or $ne are incorrect for this range.
4fill in blank
hard

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

MongoDB
db.collection.find({ score: { $[1]: 50, $[2]: 100 } })
Drag options to blanks, or click blank then click option'
Agt
Blt
Cgte
Dlte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gte or $lte would include 50 or 100, which is not asked.
Swapping the operators will cause wrong results.
5fill in blank
hard

Fill all three blanks to find documents where price is greater than or equal to 10, less than 50, and not equal to 30.

MongoDB
db.collection.find({ price: { $[1]: 10, $[2]: 50, $[3]: 30 } })
Drag options to blanks, or click blank then click option'
Agte
Blt
Cne
Dlte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $gte excludes 10.
Using $lte includes 50, which is not wanted.
Not using $ne will include price 30.