Am I doing something wrong (mongodb 'NOT' query condition)

My code,

$collection = Yii::$app->mongodb->getCollection('cases');

$condition = ['NOT', ['_id', $model->_id]];

$result = $collection->buildCondition($condition);

Results in an error “Operator ‘NOT’ requires two operands.”

I get the same error when building a find query as such:

Cases::find()->where(['NOT', ['_id' => $model->_id]])->all()

I am following the guide and documentation to the letter and yet still errors, any help would be much appreciated,


Try using $ne (not equal) operator for your query and build it yourself.


$query = Yii::$app->mongodb->getCollection('cases')->find(['_id' => ['$ne' => $model->_id]]);



I can’t get it to work with the not either. Anyone know how to use this properly?