标签: php regex mongodb compass
_id:1 email:"j@g.com"
这是我的收藏。当我写
{ email: /^J/i }
在指南针中它工作得很好,但在 php 中
$user_collection->find( ["email" => ['$regex' => "/^j/i"]] );
什么都没找到
答案 0 :(得分:0)
在您的示例 /^J/i 中,i 是请求不区分大小写搜索的选项标志。
/^J/i
i
使用 $regex 时,您需要使用单独的选项字段:
['$regex' => "^j", '$options'=>"i"]