0
0
MongoDBquery~10 mins

Regex queries 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 the 'name' field starts with 'A'.

MongoDB
db.collection.find({ name: { $regex: /^[1]/ } })
Drag options to blanks, or click blank then click option'
AA
Ba
C^A
D.*A
Attempts:
3 left
💡 Hint
Common Mistakes
Including the caret (^) inside the blank causes a syntax error.
Using lowercase 'a' will not match uppercase 'A'.
2fill in blank
medium

Complete the code to find documents where the 'email' field contains 'gmail'.

MongoDB
db.collection.find({ email: { $regex: /[1]/ } })
Drag options to blanks, or click blank then click option'
Agmail
Bgmail$
C^gmail
D^gmail$
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^gmail' matches only strings starting with 'gmail'.
Using 'gmail$' matches only strings ending with 'gmail'.
3fill in blank
hard

Fix the error in the code to find documents where 'username' ends with '123'.

MongoDB
db.collection.find({ username: { $regex: /[1]$/ } })
Drag options to blanks, or click blank then click option'
A.*123
B^123
C123$
D123
Attempts:
3 left
💡 Hint
Common Mistakes
Including '$' inside the blank causes a syntax error.
Using '^123' matches start of string, not end.
4fill in blank
hard

Fill both blanks to find documents where 'title' contains 'data' ignoring case.

MongoDB
db.collection.find({ title: { $regex: /[1]/, $options: '[2]' } })
Drag options to blanks, or click blank then click option'
Adata
Bi
Cg
D^data
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^data' matches only start of string.
Using 'g' option is for global search, not needed here.
5fill in blank
hard

Fill all three blanks to find documents where 'description' starts with 'Error' and ends with a digit.

MongoDB
db.collection.find({ description: { $regex: /^[1].*[2]$/, $options: '[3]' } })
Drag options to blanks, or click blank then click option'
AError
B\d
Ci
Dg
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to escape the backslash in '\d'.
Using 'g' option which is not needed for find queries.