Answer the question
In order to leave comments, you need to log in
How to generate a query with a regular expression in Yii2?
I use Yii2 + Yii2-mongodb
A query similar to sql is required: name LIKE "%text%"
As I understand it, in Mongo this is only regular expressions, so I write:
$q = [
'name' => [
'$regex' => $text,
'$options' => 'i',
]
];
$result['mobs'] = Biotype::find($q)->limit(10)->all();
$q = ['name' => new \MongoDB\BSON\Regex('*('.trim($text).')*', 'ig')];
$result['mobs'] = Biotype::find($q)->limit(10)->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question