在查询中找到未知运算符:>

时间:2015-03-27 05:41:57

标签: mongodb yii2

我正在使用Yii 2和Mongo DB。以下情况会引发错误。

 $query->andFilterWhere(['>', 'discount', 50]);

前端\控制器\ DealController.php

 $searchModel = new DealSearch();

 $dataProvider = $searchModel->searchDeals(Yii::$app->request->queryParams);

前端\ 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;
    }

2 个答案:

答案 0 :(得分:2)

似乎> yii扩展程序不支持<>==<mongodb等运营商。但您可以直接使用between运算符:

$query->andFilterWhere(['between', 'discount', 50, 400]);

其中400 - 是一个很大的价值(与你的目的有关)。结果查询将如下所示:

{"discount":{"$gte":50,"$lte":400}}

答案 1 :(得分:0)

尝试简单的哈希条件:

$query->andFilterWhere([
      'discount' => ['$gt'=> 50],
    ]);