2015-10-16 71 views
1

我想使用的查詢是這樣的:Yii2發現查詢中使用MongoDB的

Select * from company where id is not null order by id desc 

我使用YII2框架,MongoDB的:

$company = Company::find()->where(['id' => null])->all(); 

上述查詢工作正常,我,但我想使用按順序排列的NOT NULL條件。我怎樣才能做到這一點 ?

回答

0

嘗試 $company = Company::find()->where(['not', ['id' => null]])->orderBy('id desc')->all();

+0

它給了我一個錯誤信息:不要求兩個操作數 –

+0

嗯......怪你能告訴我其中的文件和行引發此錯誤?也許你有和我不同的Yii版本。嘗試' - >其中(['not','id',null])' –

+0

「name」:「Exception」, 「message」:「運算符'NOT'需要兩個操作數。」, 「code」:0 , 「type」:「yii \ base \ InvalidParamException」, 「file」:「/local/project/vendor/yiisoft/yii2-mongodb/Collection.php」, 「line」:906, –