正则表达式选项 /i 等在 MongoDB Compass 中不起作用

regex options /i, etc not working in MongoDB Compass

此问题与 MongoDB Compass 社区版本 1.17.0 有关。

代码 { location: /IL$|US$/i }(使用正则表达式选项)与文档过滤器工具一起使用,但在聚合 $match 管道阶段,应用程序说 Expected "[" or AggregationStage but "{" found.

没有正则表达式选项的代码,即 { location: /IL$|US$/ } 适用于过滤器和聚合工具。

如何在 MongoDB Compass 的 $match 管道阶段使用正则表达式选项?

您可以使用 RegExp 对象,例如:

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