【发布时间】:2021-01-12 07:44:35
【问题描述】:
我正在开发一个 API。我的一个端点向我返回 Spots 围绕由页面排序的 LONGITUDE 和 LATITUDE 坐标定义的点。我还发送了一个 PAGE_SIZE 用于返回一个数字或 Spots,并发送一个 MIN_DISTANCE 从何处开始作为最后一页的最后一项的页面。
我正在使用 $geoNear 键来执行此操作,这很方便,因为它还可以返回我用来进行分页的中心的距离。
遗憾的是,我现在将数据库托管在 azure COSMOS DB 上,似乎不支持 $geoNear。
https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support-36#aggregation-stages
获得最相似结果的最佳选择是什么?有一堆或 key 听起来不错,但无法找出最佳选择:($geoWithin, $geoIntersects, $near, $nearSphere, $geometry)
https://docs.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},
...
谢谢:)
【问题讨论】:
-
应该是
$near或$nearSphere。
标签: node.js mongodb azure mongoose azure-cosmosdb-mongoapi