我有一个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中的错误吗?
谢谢。我只是决定在我的应用程序中使用本机DocumentDB API。这有一个学习曲线,所以它减缓了我的速度。我希望它能够快速添加。 – nihil0