I am using Yii 2 and Mongo DB. Below condition throws error.
$query->andFilterWhere(['>', 'discount', 50]);
frontend\controllers\DealController.php
$searchModel = new DealSearch();
$dataProvider = $searchModel->searchDeals(Yii::$app->request->queryParams);
frontend\models\search\DealSearch.php
public function searchDeals($params)
{
$query = deal::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 3 ,
],
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere([
'status' => '1',
'approved_status' => '1',
//'discount >=' => $this->discount[1],
'category_id' => $this->category_id,
'state_id' => $this->state_id,
'city_id' => $this->city_id,
]);
$query->andFilterWhere(['like', 'deal_title', $this->deal_title])
->andFilterWhere(['>', 'discount', 50]);
return $dataProvider;
}
Seems, that operators like: >, <, >=, =< are not supported by mongodb yii extension. But you can use between operator directly:
$query->andFilterWhere(['between', 'discount', 50, 400]);
where 400 - is some big value(related to your purposes). And the result query will be looks like this:
{"discount":{"$gte":50,"$lte":400}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With