我正在使用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"
答案 0 :(得分:0)
我找到了解决方案
$where['$and'][] = ['$where' => "this.$male_population/this.population >= 0.5"]