mongodb - Azure CosmosDb MongoAPI nearSphere return nothing
问题描述
I'm using CosmosDB with MongoDb API and I'd like to use $nearSphere to find Documents.
Here is the exemple of one document I have in my collection "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]
}
}
I would like to find the Document with location the nearest from [26, 27]. When I execute the following request, it returns nothing. However, this same command works fine we a MongoDB database : It returns the documents order by distance with point with coordonates [26, 27].
db.locations.find({
'location': {
$nearSphere: {
$geometry: {
type: 'Point',
coordinates: [
26, 27
]
}
}
}
})
Do you know how I can make it work for Azure CosmosDB?
Thank you in advance.
解决方案
看起来我必须location.coordinates
在查询中指定 Azure CosmosDB。这是工作查询:
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
我希望这对其他人有帮助!
推荐阅读
- java - Spring 自定义 PropertyEditor / 转换器无法识别:找不到匹配的编辑器或转换策略
- python - 如何组合数据类、属性和 lru_cache
- c++ - 在同一个套接字c ++上多次写入
- filter - 具有特定列日期范围的 SUMIF
- javascript - 如何使用网站中的 jquery/javascript 检测从网络浏览器(chrome)或 webview(移动应用程序)打开的 url?
- c++ - 使用 C++ 在 FireFox 中获取活动标签 URL
- dynamics-crm - 在 Dynamics-365 的选项集中添加元数据中不存在的选项
- ios - 像在照片应用程序中一样向 AVPlayer 添加滚动播放控件
- python - 从循环中重新抛出当前项目异常
- android - 无法为andriod构建intel cs webRTC示例项目