$near error - planner returned error: unable to find index for $geoNear query $near error - planner returned error: unable to find index for $geoNear query mongoose mongoose

$near error - planner returned error: unable to find index for $geoNear query


This type of error indicates the index was not created. Usually this is due to invalid coordinate data. Perhaps load up your mongo shell and ensure your indexes are present:

mongouse yourdatabasenamedb.yourcollection.getIndexes()

You should end up with something like:

{    "v" : 2,    "key" : {      "geometry" : "2dsphere"    },    "name" : "geometry_2dsphere",    "ns" : "databasename.yourcollection",    "2dsphereIndexVersion" : 3  }

if not present, try creating the index in the shell - it will throw errors if it cannot create one.:

db.yourcollection.createIndex( { geometry : "2dsphere" } )