We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Mongo $regex not working

I am trying to do a case insensitive search with name starting from "xxx". However it doesnt seems to work. Below is my code

 $test = Test::find( array(
                array( "name" => array( '$regex' => '/^'.$query.'/i' ) ),
                "limit" => 5
            ) );

Is anything wrong with my query? appreciate any insights.



27.8k
Accepted
answer

Resolved it. Just to update for benefit of others who might need it in future.

Use MongoRegex Class. https://php.net/manual/en/class.mongoregex.php