This question is related to MongoDB Compass Community Version 1.17.0.
Code { location: /IL$|US$/i }
(with regex options) works with the Documents Filter tool, but with the Aggregations $match
pipeline stage the application says Expected "[" or AggregationStage but "{" found.
Code with no regex options, i.e., { location: /IL$|US$/ }
works in both the filter, and the aggregation tools.
How can I use regex options in the $match
pipeline stage of MongoDB Compass?
MongoDB provides the functionality to search a pattern in a string during a query by writing a regular expression. A regular expression is a generalized way to match patterns with sequences of characters. MongoDB uses Perl compatible regular expressions(PCRE) version 8.42 along with UTF-8 support.
MongoDB uses Perl compatible regular expressions (i.e. "PCRE" ) version 8.42 with UTF-8 support. For restrictions on particular syntax use, see $regex vs. /pattern/ Syntax.
Regular expression or Regex is a very important part of programming. It is usually used to find a pattern in a string.
MongoDB provides different types of comparison query operators and $in operator is one of them. This operator is used to select those documents where the value of the field is equal to any of the given value in the array.
You can use the RegExp object, e.g.:
{
email: RegExp('@gmail.com$', 'i')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With