I am trying to use the GeoSpatial search feature in MongoDB but I keep getting the following error:
codeMongo error: error code is '17007'/code
I am doing this directly in the MongoDB database page from Appery.io using the "Query" field.
According to MongoDB the error codes is due to a missing 2dSphere index.
Here is my where request: code{"location" : { "$nearSphere" : [-97.4265861, 32.68662216] }}/code
As my primary collection wasn't working, I created a "test" collection with one column called "location" setup as a geopoint. It didn't work. I then added a "name" column to the collection and it started working. I can now remove the "name" column and it continues to work. I can make it fail by changing the column name from "location" to "geo", which makes sense, but how long should it take to have the geopoint index re-established under the new name? I can then change the name back to the original name "location" and it works again.
After reading the docs here: https://devcenter.appery.io/documenta... - it reads as if the database will do this automatically but it does not seem to do so in my case. I looked at the "Manage Index" page and there is nothing about the kind of index you can create, just index on the fields in asc/desc order.
After testing with two other collections, I think I found the root issue.
For anyone that runs across this: You MUST use the exact name of the field you first create in a collection with the geopoint datatype. If you change that name later you lose the geospatial search index until you change the name back to its original name.
Given the way the "manage index" tab works you cannot create a new geospatial index ala - DB_NAME.COLLECTION_NAME.ensureIndex( { "location" : "2dsphere" } ).
If I am wrong, have missed something, or if there is a way to fix this so I can change the name of the column and keep the geospatial index, please let me know.