MongodB找到fieldvalue>其他fieldvalue * 0.5

时间:2014-10-08 17:01:24

标签: php mongodb

我正在使用php manual示例中的mangodb,如下所示

$where=array( '$and' => array( array(' class' =>12), array('marks'=>70) ) );
$cursor = $collection->find($where);

我有两个字段:population和male_population 是否有可能在male_population大于50%的情况下进行搜索?我尝试了以下但它似乎没有工作

$where['$and'][] = ['male_population' => ['$gt' => 1000]];
$where['$and'][] = ['male_population' => ['$gt' => 'this.population*0.5']];
$cursor = $collection->find($where);

也尝试了

$where['$and'][] = "this.male_population/this.population >= 0.5"

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

$where['$and'][] = ['$where' => "this.$male_population/this.population >= 0.5"]