Home > other >  Like queries in MongoDb Using PHP
Like queries in MongoDb Using PHP

Time:05-22

I want to use like queries for search in my app using MongoDb With PHP but I did not get the proper result.

Code:

$query = array("first_name" => "/.*a.*/" );
$updateResult = $this->dbCustomer->find($query);

CodePudding user response:

Try this,

$query = array("first_name" => array("$regex" => "/.a./"));
$updateResult = $this->dbCustomer->find($query);

more details, please check this out

CodePudding user response:

I got an answer and I try this and it's work perfect :

$query = array(array("first_name" => new MongoDB\BSON\Regex("$search_text", 'i')))

  • Related