More than one 2d index, not sure what to run geoNear

Why unit

    aggregate.near({
      near: coord,
      distanceField: "distance",
      maxDistance: max
    });

      

can return

{
    "name": "MongoError",
    "errmsg": "exception: geoNear command failed: { ok: 0.0, errmsg: \"more than one 2d index, not sure which to run geoNear on\" }",
    "code": 16604,
    "ok": 0
}

      

having only a 2d index in the scheme:

location: { type: [ Number ], index: '2d', sparse: true },

      

more or less, when I remove EVERYTHING from the error schema, why? o why ...

+3


source to share


1 answer


When you remove an index (or even an entire field) in your Mongoose model, it is not automatically removed from MongoDB.

Run db.<your collection name>.getIndexes()

to view all indexes. Make a note of the name

index you want to delete.



Run db.<your collection name>.dropIndex(<name of the index>)

to drop the index.

By default Mongoose tells MongoDB to (re) create indexes (" ensureIndex()

") when the application starts.

+6


source







All Articles