0
0
MongoDBquery~10 mins

Why query patterns 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 all documents where the age is greater than 25.

MongoDB
db.users.find({"age": {"$gt": [1])
Drag options to blanks, or click blank then click option'
A20
B25
C30
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using a smaller number like 15 will include too many results.
Using $lt instead of $gt will find ages less than the number.
2fill in blank
medium

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

MongoDB
db.users.find({"status": {"$in": [1])
Drag options to blanks, or click blank then click option'
A["active", "pending"]
B["active"]
C["inactive", "pending"]
D["pending", "deleted"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one status will miss some results.
Using wrong statuses will return no results.
3fill in blank
hard

Fix the error in the query to find users with name starting with 'J'.

MongoDB
db.users.find({"name": [1])
Drag options to blanks, or click blank then click option'
A"^J"
B"J"
C/^J/
D/J$/
Attempts:
3 left
💡 Hint
Common Mistakes
Using a plain string 'J' matches exact name only.
Using /J$/ matches names ending with J, not starting.
4fill in blank
hard

Fill both blanks to find users older than 30 and with status 'active'.

MongoDB
db.users.find({"age": {"$gt": [1], "status": [2])
Drag options to blanks, or click blank then click option'
A30
B"active"
C"pending"
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using 25 instead of 30 for age.
Using 'pending' instead of 'active' for status.
5fill in blank
hard

Fill all three blanks to find users with age less than 40, status 'pending', and name containing 'an'.

MongoDB
db.users.find({"age": {"[1]": [2], "status": "pending", "name": [3])
Drag options to blanks, or click blank then click option'
A$lt
B40
C/an/
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt.
Using a string instead of regex for name.