gpt4 book ai didi

php - 添加附加查询时,Doctrine MongoDB geoNear() 实例设置为 0

转载 作者:可可西里 更新时间:2023-11-01 09:15:05 25 4
gpt4 key购买 nike

我正在使用 geoNear() 来计算我的 Mongo 数据库中对象之间的距离。即使使用 ->field('name')->equals($name) 等附加字段过滤器,查询也能完美运行...

这会自动填充对象上的映射字段@ODM\Distance。

$this->getQueryBuilder()
->geoNear((float) $query['near_longitude'], (float) $query['near_latitude'])
->spherical(true)
->distanceMultiplier(self::EARTH_RD_KM);

如果我添加一个 ->field('id')->in($array) 但是这个距离突然变为 0。我不太确定信息在哪里丢失。这是对 $in 在 MongoDB 上的工作方式的限制吗?

最佳答案

你需要使用“maxDistance”函数

像这样;

$this->getQueryBuilder()
->geoNear((float) $query['near_longitude'], (float)$query['near_latitude'])

->spherical(true)

->maxDistance(self::YOUR_DESIRED_KM_RADIUS / self::EARTH_RD_KM)

->distanceMultiplier(self::EARTH_RD_KM);

这样它会为您的查询设置一个半径。

关于php - 添加附加查询时,Doctrine MongoDB geoNear() 实例设置为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34094903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com