2014-10-25 2 views
2

나는 meteor를 사용하여 mongodb 컬렉션을 쿼리합니다. 바로 지금이 위치가 2dsphere 인덱스 인 쿼리입니다.MongoDb 위치 배열에있는 배열

 messages.find({ 
     location: 
      { 
       $geoWithin :{$centerSphere : [ [ longitude, latitude ] , radius ] } 
      } 
     }); 

내가 '위치'2dsphere 인덱스의 배열이었다 내가 배열이 longitude, latituderadius 내 요소를 포함입니다 어떤 항목을 원하는 경우이 쿼리에서 변경해야? 당신은 당신이

> db.test.find({ 
    "locs.loc" : { 
      "$geoWithin" : { "$centerSphere" : [ [ longitude, latitude ] , radius ] } 
     } 
    } 

처럼이 작품을 원하는 쿼리를 수행 할 수 있습니다

> db.test.ensureIndex({ "locs.loc" : "2dsphere }) 

를 사용하여 2dsphere 지수를 구성하는 경우와 함께 문서를

답변

3

때문에 인덱스 배열에

{ 
    "_id" : ObjectId("544e65dc0d86a53a8b32f7d0"), 
    "locs" : [ 
     { 
      "loc" : { 
       "type" : "Point", 
       "coordinates" : [ 
        -71.97, 
         43.77 
       ] 
      } 
     }, 
     { 
      "loc" : { 
       "type" : "Point", 
       "coordinates" : [ 
        -63.97, 
        48.77 
       ] 
      } 
     } 
    ] 
} 

같은 구조 멀티 키이며 문서의 배열 요소마다 하나의 색인 항목을 만듭니다.