We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.6k
Accepted
answer

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

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