Issue with geo index in mongoAtlas

34 views Asked by At

I´ve migrating my last mLab application with heroku to the new MongoAtlas platform. I found some issues when trying to create geo indexes for my collections.

Here is how I used to integrate the index in the mLab tool:

db.OpenDataMadrid.createIndex( {“location.coordinates” : “2dsphere” } )
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2d” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2dsphere” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2d” } )

And now my new geo indexes for both collections are like this:

{
    “mappings”: {
        “dynamic”: true,
        “fields”: {
            “location”: {
                “fields”: {
                    “coordinates”: [
                        {
                            “dynamic”: true,
                            “type”: “document”
                        },
                        {
                            “indexShapes”: true,
                            “type”: “geo”
                        }
                    ]
                },
                “type”: “document”
            }
        }
    }
}

But when I run the application and the $geoquery is done I receive the following error:

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

Any help creating 2d and 2dphere indexes?

I’ve also try to create the index to the location variable instead of location.coordinates but it doesn’t work either.

Thanks in advance!

0

There are 0 answers