首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure CosmosDb MongoAPI nearSphere不返回任何内容

Azure CosmosDb MongoAPI nearSphere不返回任何内容
EN

Stack Overflow用户
提问于 2021-03-18 01:50:07
回答 1查看 32关注 0票数 0

我正在使用带有MongoDb应用程序接口的CosmosDB,我想使用$nearSphere来查找文档。

下面是我收藏的“locations”中的一个文档的例子:

代码语言:javascript
复制
{
    "_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按距离返回文档。

代码语言:javascript
复制
db.locations.find({
  'location': {
    $nearSphere: {
      $geometry: {
        type: 'Point',
        coordinates: [
          26, 27
        ]
      }
    }
  }
})

你知道我如何让它在Azure CosmosDB上工作吗?

提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2021-03-19 01:33:13

看起来,对于Azure CosmosDB,我必须在查询中指定location.coordinates。以下是工作查询:

代码语言:javascript
复制
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

我希望这能帮助其他人!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66678574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档