0

First time using MongoDD. I have been combing the internet for hours trying to figure out what I am doing wrong. MongoDB is telling me that there is no index present after executing a geo query.

I have included the error. Any ideas?

The Schema

var locationPolygonSchema = new Schema({
  type: {
    type: String,
    index: true,
    default: 'Polygon'
  },
  loc: {
    type: [Number],
    index: '2dsphere'
  }
});

var developerSchema = new Schema({
    locationPolygon: locationPolygonSchema
});

developerSchema.index({locationPolygon: 1});
developerSchema.set('autoIndex', true);

The Document

{
    ...
 locationCoords: [-122.47020789999999, 37.6879241]
 locationName: "Daly City, CA, USA"
 locationPolygon: {
  type: "Polygon",
  coordinates: [[[9129,1773], [8291, -4891]]]
 },
 locationRadius: 20
    ...
}

The Error

{
 "$err": "Unable to execute query: error processing query: ns=whenrecruited.developers limit=21 skip=0" +
  "Tree: GEONEAR  field=locationPolygon maxdist=1.79769e+308 isNearSphere=0" +
  "Sort: {}" +
  "Proj: {}" +
  "planner returned error: unable to find index for $geoNear query",
 "code": 17007,
 "message": "Unable to execute query: error processing query: ns=whenrecruited.developers limit=21 skip=0" +
  "Tree: GEONEAR  field=locationPolygon maxdist=1.79769e+308 isNearSphere=0" +
  "Sort: {}" +
  "Proj: {}" +
  "planner returned error: unable to find index for $geoNear query",
 "name": "MongoError"
}
jjhenry
  • 515
  • 2
  • 5
  • 8
  • Can you execute db.collection.getIndexes() and check if the index is present? – CS_noob Jul 18 '16 at 06:10
  • 1
    Your schema doesn't seem to match your document example. E.g., your schema has `{type:_, loc:_}` and your document has `{type:_, coordinates:_}`. Also, you put indexing on every field in your schema (including inside the GeoJSON object). Could you confirm that the schema actually works for inserting and querying documents? – kevinadi Jul 18 '16 at 06:36
  • @CS_noob I didnt get a notification, apologies for the delay. Will try this evening. – jjhenry Jul 20 '16 at 18:19
  • @KevinAdistambha will correct this and get back to you, thanks a ton! – jjhenry Jul 20 '16 at 18:20
  • I reworked everything and it seems to be working now. Thanks for your suggestions!! – jjhenry Jul 26 '16 at 06:27

0 Answers0