Quick Answer
$regex filters documents where a string field matches a regular expression. db.users.find({name: {$regex: "^alice", $options: "i"}}) finds users whose name starts with "alice" (case-insensitive). Performance warning: regex queries without a text index or leading wildcard can't use indexes and cause full collection scans. Anchor patterns to the start (^) when possible.
Answer
$regex performs pattern matching on string fields and is useful for partial text searches.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
MongoDB interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Perfect for freshers and experienced candidates.