使用Mongo API的地理空间索引查询不适用于Azure CosmosDB(DocumentDB) [英] Geospatial index querying doesn't work on Azure CosmosDB (DocumentDB) using the Mongo API

查看:54
本文介绍了使用Mongo API的地理空间索引查询不适用于Azure CosmosDB(DocumentDB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有集合restaurants的Azure CosmosDB,其中字段geoJSON以geoJSON格式指定餐厅的位置.我正在使用MongoDB API来访问它.

I have an Azure CosmosDB with a collection restaurants where a field geoJSON specifies the location of a restaurant in geoJSON format. I am using the MongoDB API to access this.

当我使用mongo shell登录数据库时,可以使用db.restaurants.find()查看所有文档.我使用db.restaurants.createIndex( {geoJSON: "2dsphere"})创建了2dsphere地理空间索引.

When I log into the DB using the mongo shell, I am able to see all the documents using db.restaurants.find(). I created a 2dsphere geospatial index using db.restaurants.createIndex( {geoJSON: "2dsphere"}).

输出:

{
    "_t" : "CreateIndexesResponse",
    "ok" : 1,
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 3,
    "numIndexesAfter" : 4
}

但是,在运行db.restaurants.getIndexes()时,我仍然只看到三个索引. 问题表示不允许建立索引.还是这样吗?

However, upon running db.restaurants.getIndexes(), I still see only three indexes. This question says that indexing is not allowed. Is this still the case?

此外,似乎还有一个名为

Furthermore, there seems to be an index called

{
            "v" : 1,
            "key" : {
                    "DocumentDBDefaultIndex" : "2dsphere"
            },
            "name" : "DocumentDBDefaultIndex_2dsphere",
            "ns" : "<redacted>"
}

,但是执行地理空间查询不会返回任何结果.

,but executing a geospatial query returns nothing.

db.restautants.find({DocumentDBDefaultIndex: {$near: {$geometry: {type: "Point", coordinates: [24.9430111, 60.166608]}, $maxDistance: 1000}}})

如何使用mongo shell对该索引执行地理空间查询?这是CosmosDB中的错误吗?

How can I execute geospatial queries against this index using the mongo shell? Is this a bug in CosmosDB?

推荐答案

根据您的描述,我已就此问题进行了检查.快速方法是将 MongoChef 与Azure Cosmos数据库.根据我的测试,db.brucetest1.createIndex({loc:"2dsphere"})无法应用于集合.此外,我发现DocumentDB自动在位置字段DocumentDBDefaultIndex上创建2dsphere索引,然后放下我的文档,并按如下所示插入文档:

According to your description, I checked this issue on my side. For a quick way, I use MongoChef with the Azure Cosmos DB. Based on my test, db.brucetest1.createIndex({loc:"2dsphere"}) could not be applied to the collection. Moreover, I found DocumentDB automatically creates a 2dsphere index on the location field DocumentDBDefaultIndex, then I drop my documents, and insert the documents as follows:

db.brucetest.insertMany([
   {DocumentDBDefaultIndex : { type: "Point", coordinates: [ -73.97, 40.77 ] },name: "Central Park",category : "Parks"},
   {DocumentDBDefaultIndex : { type: "Point", coordinates: [ -73.88, 40.78 ] },name: "La Guardia Airport",category : "Airport"}
])

通过以下查询,我可能会遇到您的问题:

With the following query, I could encounter your issue:

db.brucetest.find({DocumentDBDefaultIndex:{$near:{$geometry:{type:"Point",coordinates:[-73.88, 40.78]}}}})

基于您提到的类似的问题 ,我假设Azure CosmosDB的MongoDB兼容性层中尚未实现创建/更新索引和地理空间索引查询功能.此外,您可以在此处添加反馈,或等待这些功能发布

Based on the similar issue your mentioned, I assumed that the creating/updating index and Geospatial indexes querying features have not been implemented in the MongoDB Compatibility layer of Azure CosmosDB. Moreover, you could add your feedback here or wait for these features released.

这篇关于使用Mongo API的地理空间索引查询不适用于Azure CosmosDB(DocumentDB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆