How to query the sum of two fields in yii2-mongodb is greater than 10

  mongodb, question

Problem description

AR query, YII2 framework, if the query is stored in MongoDB data, the sum of the two fields is greater than 10

The environmental background of the problem and what methods have you tried?

In YII2, if you are querying MySQL data, you can use [‘>’,’like+comment’,10], which is not allowed in MongoDB

Related codes

return $provider = new ActiveDataProvider([
 'query'      => Feeds::Find()->where(['>=','likes+comment' ,0]),
 'pagination' => [
 'pageSize' => 10,
 ],
 ]);

In fact, it can be done, but few people do it for performance reasons. Consider putting the sum of likes+comments in a field, so that only one field condition is required when querying, and an index can be established on this field to speed up the query.