시도 :
1 단계 :
이 스키마에 위치 필드를 추가하고에 2dsphere 색인을 만들 수 있습니다.
location: { type: [Number], index: '2dsphere' }
또한 동적 색인을 만들 수 있습니다
db.collection.createIndex({ <location field> : "2dsphere" })
2 단계
이제 $ geoNear로 집계 쿼리를 만들 : 당신이 어떤 조건을 통과 할 수
var aggregateQuery = [{
"$geoNear": {
"near": {
"type": "Point",
"coordinates": [options.longitude, options.latitude]
},
"distanceField": 'dis',
"distanceMultiplier": .001,
"spherical": true,
"query": **conditions**
}
}];
을 검색어 매개 변수
db.collectionname.aggregate(aggregateQuery).exec(function(err, result){
// use result here
})
참고 : 경도 위치 배열의 첫번째 다음 위도를 저장해야합니다. 자세한 내용은
은이 링크를 참조 :이 도움이 https://docs.mongodb.com/manual/reference/command/geoNear/
희망!
UPDATE은 :
db.collectionname.aggregate([
{$match: {
$text: {$search: "text"} ,
location: {$geoWithin: {$centerSphere: [[ longitude, latitude], points]}}
}}])
참고 : 지리 인덱스가 사용되지 않습니다!
대한 추가 정보를 원하시면이 링크 http://docs.mongodb.org/manual/reference/operator/query/geoWithin/
MongoDB를의 사용 geonear 쿼리를 참조하십시오. –