【发布时间】:2014-06-17 16:59:02
【问题描述】:
我有一个模型,其地址字段类型为 Location(KeystoneJS 地址 + 地理坐标)。据我了解,该字段中的地理坐标被索引为 2dSphere。
但是,如果我尝试使用 MongooseJS near 函数进行查询,它会返回错误:
var point = [3.2642048999999815241,50.830799100000090124];
Challenge.model.find(
{status: 1}
)
.where('location')
.near({
center: point,
maxDistance: maxDistance,
spherical: true
})
.populate('waypoints')
.exec(function(err, challenges) {
if(err) return res.apiError('1000', Errors['1000']);
return res.apiResponse({
challenges: challenges
});
});
返回:
MongoError: can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { status: 1, location: { $nearSphere: [ 3.264204899999982, 50.83079910000009 ], $maxDistance: 1000 } }
我不明白为什么它会为此引发错误。
【问题讨论】:
标签: javascript mongodb mongoose keystonejs