命令在 mongodb 指南针中有效,但在 php 中无效

时间:2021-08-01 14:28:59

标签: php regex mongodb compass

_id:1
email:"j@g.com"

这是我的收藏。当我写

{ email: /^J/i  }

在指南针中它工作得很好,但在 php 中

$user_collection->find(
    ["email" => ['$regex' => "/^j/i"]]
);

什么都没找到

1 个答案:

答案 0 :(得分:0)

在您的示例 /^J/i 中,i 是请求不区分大小写搜索的选项标志。

使用 $regex 时,您需要使用单独的选项字段:

['$regex' => "^j", '$options'=>"i"]