我试图通过使用MongoDB的find方法查询某个点周围的纬度和经度点来使用MongoDB的地理空间索引。我不断收到错误:MongoError:找不到任何特殊索引:2d(需要索引),2dsphere(需要索引)
MongoError: can't find any special indices: 2d (needs index), 2dsphere (needs index)
我不知道在哪里的文档谷歌搜索了大约一个小时后,就是这个。我也找不到任何好的解释。下面是我用猫鼬创建的模式:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var EventSchema = new Schema ({
name: String,
description: String,
location: {type: [String], index: '2dsphere'},
time: Date,
photo: Buffer,
activity: String
});
mongoose.model('Event', EventSchema);
我然后使用找到的方法来找到其他事件各地用户提供的点文件。
var maxDistance = 0.09;
var lonLat = {$geometry: {type: 'Point', coordinates: [34.09,124.34] }};
Event.find({
'geo': {
$near: lonLat,
$maxDistance: maxDistance
}
}).exec(function(err, events) {
if(err) {
throw err;
} else {
return events;
}
});
我在这里有什么语法错误?我错过了一些巨大的东西?除this link之外,任何文档的任何URL都会很好。
你真的做了索引吗? http://docs.mongodb.org/manual/core/geospatial-indexes/ quig搜索mongodb 2d索引 – Sammaye