我正在使用MongoDB,PHP驱动程序和Google Maps。由于Google Maps对Longitude进行了绕圈(在某些情况下,LEFT经度可能会大于RIGHT经度),因此我试图获得相当于MySQL的而不是在MongoDB中的工作。MongoDB等价于“NOT BETWEEN”
有没有人成功地使用了MongoDB的“$或”操作符来模拟NOT BETWEEN?
这里是我的(失败)的尝试至今:
// If the LEFT longitude is greater
if ($longitude_left > $longitude_right) {
$params = array(
'$or' => array(
'longitude' => array('$gte' => $longitude_left, '$lte' => $longitude_right)
)
);
}
// By default, the RIGHT longitude is greater
else {
$params = array(
'longitude' => array(
'$gte' => $longitude_left, '$lte' => $longitude_right
)
);
}
$mongo = new Mongo();
$cursor = $mongo->energy->plants->find($params);