我正在使用带有MongoDb应用程序接口的CosmosDB,我想使用$nearSphere来查找文档。
下面是我收藏的“locations”中的一个文档的例子:
{
"_id": {
"$oid": "60523b3dd72e4d4aa21f473b"
},
"data": [{
"Indicateur": "pr50mm",
"Value": 0,
"score": 0,
"Exposure": "low"
}],
"Domain": "EU-CORDEX",
"GCMS": "ICHEC-EC-EARTH",
"RCMS": "RACMO22E",
"Scenario": "rcp85",
"Horizon": "Medium (1941-1970)",
"location": {
"type": "Point",
"coordinates": [26.32, 27.25]
}
}我想找到位置离26,27最近的文档。当我执行以下请求时,它什么也不返回。然而,同样的命令在MongoDB数据库中工作得很好:它通过点和坐标26、27按距离返回文档。
db.locations.find({
'location': {
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [
26, 27
]
}
}
}
})你知道我如何让它在Azure CosmosDB上工作吗?
提前谢谢你。
发布于 2021-03-19 01:33:13
看起来,对于Azure CosmosDB,我必须在查询中指定location.coordinates。以下是工作查询:
db.locations.find({
'location.coordinates': {
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [
26, 27
]
}
}
}
})关于$nearSphere的这个例子帮助了我:https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cosmos-db/mongodb-feature-support.md
我希望这能帮助其他人!
https://stackoverflow.com/questions/66678574
复制相似问题