我有一个地址字段类型为 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: 找不到任何特殊索引: 2d (needs index), 2dsphere (needs index), for: { status: 1, location: { $nearSphere: [ 3.264204899999982, 50.83079910000009 ], $maxDistance: 1000 } }
我不明白为什么它会为此引发错误。