Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

more than one 2d index, not sure which to run geoNear on

Why aggregate

    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 in the scheme the only 2d index:

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

more or less when i remove EVERYTHING from the scheme the error doenst change why? o why...

like image 776
Nik Terentyev Avatar asked Feb 11 '23 22:02

Nik Terentyev


1 Answers

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 of the index you want to remove.

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

By default, Mongoose tells MongoDB to (re-)create indexes ("ensureIndex()") when you start your app.

like image 176
RickN Avatar answered Feb 14 '23 21:02

RickN