MongoDB query with condition or

Using MongoDB on Yii2 I’m trying to get all rows from table that contain a value I’m looking for using query find with where and or but my query return a blank page but in my table there are 2 rows minimum that contain the value I’m searching for

$model = Querytest::find()->where(
                         ['or', 
                         ['like', 'title', '%' . $key . '%', false] , 
                         ['like', 'keyword', '%' . $key . '%', false]
                         ])
                ->all();
 return $model;

I did a try with :

$model = Querytest::find()->where(
                         ['$or', 
                         ['like', 'title', '%' . $key . '%', false] , 
                         ['like', 'keyword', '%' . $key . '%', false]
                         ])
                ->all();
 return $model;

But I get error message say : Illegal offset type

I did find the solution it’s is

$model = Websites::find()
                ->where(['or', ['like', 'title', $key ] , ['like', 'keyword', $key ]])
                ->all();
        return $model;
1 Like