第一次使用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"
}