mongodbmongodb-compass

regex options /i, etc not working in MongoDB Compass


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?


Solution

  • You can use the RegExp object, e.g.:

    {
      email: RegExp('@gmail.com$', 'i')
    }