2017-05-12 33 views
0

我有一个Azure CosmosDB,集合restaurants,其中字段geoJSON指定geoJSON格式的餐厅位置。我正在使用MongoDB API来访问它。地理空间索引查询在使用Mongo API的Azure CosmosDB(DocumentDB)上不起作用

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

输出:

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

然而,一旦运行db.restaurants.getIndexes(),我仍然看到只有三个指标。 This问题说,索引是不允许的。这仍然是这样吗?

而且,似乎是一个被称为指数

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

,但执行地理空间查询返回任何内容。

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

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

回答

1

根据你的描述,我在这边查了这个问题。为了快速的方式,我使用了Azure Cosmos DB中的MongoChef。根据我的测试,db.brucetest1.createIndex({loc:"2dsphere"})无法应用于收藏。此外,我发现DocumentDB上自动创建位置字段DocumentDBDefaultIndex一个2dsphere指数,然后我把我的文档,然后将文件如下:

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"} 
]) 

用下面的查询,我可能会遇到的问题:

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

基于类似issue你提到的,我认为,创建/更新指标和地理空间索引查询功能还没有在Azure中CosmosDB的MongoDB的兼容层中实现。此外,您可以添加您的反馈here或等待这些功能发布。

+0

谢谢。我只是决定在我的应用程序中使用本机DocumentDB API。这有一个学习曲线,所以它减缓了我的速度。我希望它能够快速添加。 – nihil0

相关问题