0

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!

Joe
  • 25,000
  • 3
  • 22
  • 44
  • What does the data look like? – Joe Oct 12 '21 at 15:35
  • Hi, the data of an object is like this: _id : 5adcc9a162c88a02b8515d8c Reference : "Yelp" Name : "De la Vega" Address : "Parque del Arroyo de la Vega" ZipCode : "Arroyo de la Vega, Madrid" Phone : "" Category : "Asadores" Reviews : 2 Price : "€€€€" Type : "restaurant" location : Object type : "Point" coordinates : Array 0 : -3.6264837 1 : 40.5388232 Rating : 3 – Alvaro Blanco Muñoz Oct 12 '21 at 21:18

0 Answers0