【问题标题】:regex options /i, etc not working in MongoDB Compass正则表达式选项 /i 等在 MongoDB Compass 中不起作用
【发布时间】:2019-09-23 07:09:43
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: mongodb mongodb-compass


    【解决方案1】:

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

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

    【讨论】:

    • 您使用的是什么版本的指南针?我刚刚尝试了最新的稳定版(1.20.3),它似乎工作正常。
    • 它通过更改缩进并将所有内容保持在一行对我有用。 (指南针版本 1.21.2)
    猜你喜欢
    • 1970-01-01
    • 2017-03-17
    • 2020-07-08
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多