Complete the code to find documents where the 'name' field starts with 'A'.
db.collection.find({ name: { $regex: /^[1]/ } })The regex /^A/ matches strings starting with 'A'. Here, the caret (^) is outside the blank, so only 'A' is needed.
Complete the code to find documents where the 'email' field contains 'gmail'.
db.collection.find({ email: { $regex: /[1]/ } })The regex /gmail/ matches any string containing 'gmail' anywhere.
Fix the error in the code to find documents where 'username' ends with '123'.
db.collection.find({ username: { $regex: /[1]$/ } })The dollar sign ($) is already outside the blank, so inside the blank we only put '123'.
Fill both blanks to find documents where 'title' contains 'data' ignoring case.
db.collection.find({ title: { $regex: /[1]/, $options: '[2]' } })The regex /data/ matches 'data' anywhere. The option 'i' makes the search case-insensitive.
Fill all three blanks to find documents where 'description' starts with 'Error' and ends with a digit.
db.collection.find({ description: { $regex: /^[1].*[2]$/, $options: '[3]' } })The regex /^Error.*\d$/ matches strings starting with 'Error' and ending with a digit. The 'i' option ignores case.