2013-08-31 4 views
0

nodejs의 위치 기반 응용 프로그램에서 작업 중입니다. MongoDB의의 v2.4.4
- - 나는
사용하고있는 기본 nodejs MongoDB를 드라이버 (https://github.com/mongodb/node-mongodb-native)
가 - 버전 0.10.0
노드에서 mongodb 명령과 함께 커서 메소드 사용

을 nodejs 나는 하나의 콜렉션의 모든 문서에 지리 공간 색인 (2dsphere)가 있습니다. 필드는 다음과 같이이다 :

{ "loc" : { "type" : "Point", "coordinates" : [ -122.5418261, 38.0047656 ] } } 

컬렉션의 이름은 '장소'

특정 지점에 근접 기반으로 데이터를 조회하려면, 내가 사용하고 코드입니다 :

var query = { 
      geoNear:"Venue", 
      near : { type : "Point" , 
       coordinates: [ searchParams.longitude, searchParams.latitude ] } , 
      spherical : true, 
      limit: 10000, 
      maxDistance : searchParams.radius 
     }; 


mongodbconnection.command(query, function(error, data){ 

}); 

지형 공간 쿼리가 정상적으로 작동합니다. 그러나 나는 skip()과 limit() 같은 커서 객체 메소드를 사용하여 결과를 더 필터링하려고한다. 그러나 콜백에서 반환 된 데이터 개체는 커서가 아닙니다. 그렇다면 skip()과 limit()은 어떻게 사용합니까?

답변

0
center = [-122, 37]; 
    radius = 80; 
    var query = {"loc" : {"$within" : {"$center" : [center, radius]}}}; 


    collection.find(query).skip(2000).toArray(function(err,data){ 


     console.log(data.length); 

    }); 

씨 : 당신은 (대상으로), 또는 커서와 같은 위의 예에서와 같이 커서 옵션을 포함 할 수

db.collection('Venue', function(err, venues) { 
    // you might want to cache collection handler after 
    if (!err) { 
    venues.find({ $near: { $geometry: { type: 'Point', coordinates: [ searchParams.longitude, searchParams.latitude ] }, $maxDistance: searchParams.radius }, { limit: 32 }).toArray(function(err, data) { 
     if (!err) { 
     console.log(data); 
     } else { 
     console.error(err); 
     } 
    }); 
    } else { 
    console.error(err); 
    } 
}); 

: MongoDB Geospatial Query Count Issue (Always 100)

+1

$되지 않습니다 내 ... $를 사용 geoWithin (http://docs.mongodb.org/manual/reference/operator/geoWithin/#op._S_geoWithin) 또는 $ nearSphere (http://docs.mongodb.org /manual/reference/operator/nearSphere/#op._S_nearSphere). $ geoWithin을 사용하는 경우 경계 지오메트리로 센터를 사용하십시오 (http://docs.mongodb.org/manual/reference/operator/centerSphere/#op._S_centerSphere). $ geoWithin은 거리에 따라 결과를 정렬하지 않기 때문에 $ nearSphere보다 빠릅니다. – Shuaib

0

대신 데이터베이스에 직접 .command을 실행 .find을 사용하십시오 익숙해지면 명령 줄 내에서 확장 기능을 사용할 수 있습니다.

관련 문제