タイプ 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 (インデックスが必要)、2dsphere (インデックスが必要)、for: { status: 1, location: { $nearSphere: [ 3.264204899999982, 50.83079910000009 ], $maxDistance: 1000 } }
これでエラーが発生する理由がわかりません。