我正在开发一个API。我的端点之一返回点,这个点是由LONGITUDE & LATITUDE按页面排列的同弦定义的。我还发送了一个PAGE_SIZE作为数字或Spot返回,以及一个MIN_DISTANCE从哪里开始页面,这是最后一页的最后一项。
我使用$geoNear键来实现这一点,这很方便,因为它还为我返回用于分页的中心的距离。
遗憾的是,我现在托管的数据库位于蔚蓝宇宙DB上,而且似乎不支持$geoNear。
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support-36#aggregation-stages
获得最相似结果的最佳选择是什么?有一堆或键听起来不错,但无法找到最好的选择:($geoWithin,$geoIntersects,$near,$nearSphere,$geometry)
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support-36#geospatial-operators
Spots.aggregate
([
{
$geoNear: {
near: {
type: "Point",
coordinates: [ LONGITUDE, LATITUDE ]
},
distanceField: "location.distance",
spherical: true,
minDistance: MIN_DISTANCE,
maxDistance: DISTANCE * 1000,
query: {
$and: [
...
]
}
}
},
{ $match: {} },
{ $limit : PAGE_SIZE},
...谢谢:)
发布于 2021-01-12 15:44:37
我最终使用了$nearSphere,得到了几乎相同的结果,除了手动计算的距离。
Spots.aggregate(
[
{
$match: {
$and: [
{
location: {
$nearSphere: {
$geometry: {
type : "Point",
coordinates : [ LONGITUDE, LATITUDE ]
},
$minDistance: MIN_DISTANCE,
$maxDistance: MIN_DISTANCE * 1000
}
}
},
...
]
}
},
{ $limit : PAGE_SIZE},
...https://stackoverflow.com/questions/65679794
复制相似问题