2014-06-16 3 views
1

위치 유형 (KeystoneJS 주소 + 지역 좌표) 인 주소 필드가있는 모델이 있습니다. 내가 이해하는 것처럼이 필드의 지리적 좌표는 2dSphere로 색인됩니다.몽구스 JS가 Keystone 위치 필드 근처에서 작동하지 않습니다.

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 } }

나는 기능 근처 MongooseJS와 쿼리하려고하면

그러나, 그것은 오류를 반환합니다.

답변

2

몽구제의 버그 인 것 같습니다. 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 
    }); 
}); 
관련 문제