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

Vla*_*mir 5 mongodb mongodb-compass

此问题与 MongoDB Compass Community Version 1.17.0 有关。

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

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

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

小智 12

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

{
  email: RegExp('@gmail.com$', 'i')
}
Run Code Online (Sandbox Code Playgroud)