我已经将我最后一个使用 heroku 的 mLab 应用程序迁移到新的 MongoAtlas 平台。我在尝试为我的收藏创建地理索引时发现了一些问题。
以下是我在 mLab 工具中集成索引的方式:
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2dsphere” } )
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2d” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2dsphere” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2d” } )
现在我的两个集合的新地理索引是这样的:
{
“mappings”: {
“dynamic”: true,
“fields”: {
“location”: {
“fields”: {
“coordinates”: [
{
“dynamic”: true,
“type”: “document”
},
{
“indexShapes”: true,
“type”: “geo”
}
]
},
“type”: “document”
}
}
}
}
但是当我运行应用程序并且 $geoquery 完成时,我收到以下错误:
Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=1Tree: GEONEAR field=location.coordinates maxdist=2 isNearSphere=0
2021-10-10T07:29:36.472781+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.472781+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.472787+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
2021-10-10T07:29:36.585612+00:00 app[web.1]: Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=300Tree: $and
2021-10-10T07:29:36.585620+00:00 app[web.1]: Type $eq “restaurant”
2021-10-10T07:29:36.585620+00:00 app[web.1]: Puntuacion $gt 3.5
2021-10-10T07:29:36.585621+00:00 app[web.1]: GEONEAR field=location.coordinates maxdist=250 isNearSphere=0
2021-10-10T07:29:36.585622+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.585622+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.585628+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
创建 2d 和 2dphere 索引有什么帮助吗?
我也尝试创建指向位置变量的索引,location.coordinates
但它也不起作用。
提前致谢!