Text Matching with Regex
$regex matches text patterns. Anchors like ^ are faster with an index. Use the i option for case insensitive.
Example
db.students.find({ name: { $regex: /^a/i } })
db.students.find({ name: { $regex: "son$" } })Exercise
Names starting with A.
{ name: /a/ }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.