首页 > 解决方案 > 如何在 PHP mongodb 驱动程序中比较 mongodb 中同一表的 2 列?

问题描述

请通过检查以下示例为我提供对我的问题的准确答案:

比如表:员工有字段(age1,age2)

我想做 SELECT 查询

Select count(*) From Employees Where age1 < age2

如何在mongodbphp 驱动程序功能中做到这一点?

标签: phpmongodb

解决方案


尝试以下操作:-

$db->empoyees->find( array('$where' => 'this.age1 < this.age2'  ) );

或者

$db->empoyees->find(array('age1' => array('$lt' => 'age2')));

推荐阅读