第一次使用MongoDD。我一直在梳理互联网几个小时试图弄清楚我做错了什么。 MongoDB告诉我在执行地理查询后没有索引。
我已经包含了错误。有什么想法吗?
架构
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);

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

错误
{
"$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"
}