1

タイプ 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 } }

これでエラーが発生する理由がわかりません。

4

1 に答える 1

3

MongooseJS のバグのようです。MongoDB クエリ表記を使用すると、次のように機能します。

Challenge.model.find(
        {
         status: 1, 
         "location.geo": {$near: { $geometry:{ type: "Point", coordinates: location }, $maxDistance: maxDistance}}},
         "-__v -updatedOn -createdOn -slug")
.populate('waypoints')
.exec(function(err, challenges) {
    if(err) return res.apiError('1000', Errors['1000']);
    return res.apiResponse({
        challenges: challenges
    });
});
于 2014-06-17T08:59:02.667 に答える