2014-08-30 4 views
0

mongodb 지형 공간 인덱스를 사용하여 타일 맵을 구현하려고합니다.몽구스 지형 공간 인덱스 범위 설정

var TileSchema = mongoose.Schema({ 
    location: [Number], 
    tile_type: Number 
}); 

TileSchema.index({location: '2d'}, {min: 500, max: 500}); 

하지만이있는 타일을 저장하려고하면 아무리 내가 '최소'와 '최대'속성에 대한 설정 어떤 값을 여전히 오류가 발생하지 : 나는 다음과 같은 코드 부분을 포함하는 서버 스크립트를 실행 예 경도 180에서. 몽구스에서 이러한 속성을 설정하는 올바른 방법일까요?

다음은 오류를 발생시키지 않습니다.

Tile.on('index', function (err) { 
    if (err) console.error(err); // error occurred during index creation 
}) 

내가 최대분을 할당하려 디버그 로그 500과 -500 :

Listening on port 1337... 
Mongoose: tiles.ensureIndex({ location: '2d' }) { safe: undefined, background: true, max: 500, min: -500 } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -48, -48 ], [ 48, 48 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -48, -48 ], [ 48, 48 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -64, -48 ], [ 32, 32 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -112, -48 ], [ -32, 32 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -176, -48 ], [ -96, 32 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -240, -64 ], [ -160, 32 ] ] } } }) { fields: undefined } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -272, -64 ], [ -192, 16 ] ] } } }) { fields: undefined } 
{ [MongoError: point not in interval of [ -180, 180 ] :: caused by :: { 0: -186.0, 1: -24.0 }] name: 'MongoError' } 
Mongoose: tiles.insert({ __v: 0, _id: ObjectId("54034534c480de3512a82523"), tile_type: 100, location: [ -219, -27 ] }) {} 
{ [MongoError: insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('54034534c480de3512a82523'), location: [ -219, -27 ], tile_type: 100, __v: 0 }] 
    name: 'MongoError', 
    code: 16755, 
    err: 'insertDocument :: caused by :: 16755 Can\'t extract geo keys from object, malformed geometry?: { _id: ObjectId(\'54034534c480de3512a82523\'), location: [ -219, -27 ], tile_type: 100, __v: 0 }' } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -288, -64 ], [ -208, 16 ] ] } } }) { fields: undefined } 
{ [MongoError: point not in interval of [ -180, 180 ] :: caused by :: { 0: -194.0, 1: -24.0 }] name: 'MongoError' } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -272, -64 ], [ -192, 16 ] ] } } }) { fields: undefined } 
{ [MongoError: point not in interval of [ -180, 180 ] :: caused by :: { 0: -186.0, 1: -24.0 }] name: 'MongoError' } 
Mongoose: tiles.find({ location: { '$geoWithin': { '$box': [ [ -272, -64 ], [ -192, 16 ] ] } } }) { fields: undefined } 
{ [MongoError: point not in interval of [ -180, 180 ] :: caused by :: { 0: -186.0, 1: -24.0 }] name: 'MongoError' } 

같아요 무시할 수 처음에 쿼리를 찾을 수 있습니다, 그들은 게임 클라이언트에서 내지도를 스크롤하는 것만으로 효과가 있습니다.

+1

나는 완전히 이해하지 못한다. 최소 및 최대 왜 무엇을 설정합니까? 오류를 일으키는 삽입과 오류를 표시합니다. 몽구스 디버깅을 켜고 인덱싱 작업과 삽입에 대한 설명을 보여줍니다. – wdberkeley

+0

질문이 업데이트되었습니다. 지금은 더 분명해지기를 바랍니다. 나는 이것과 비슷한 것을 얻고 싶기 때문에 min과 max를 설정하려고한다. http://blog.nodeknockout.com/post/35215504793/the-wonderful-world-of-geospatial-indexes-in-mongodb –

+0

잘 작동한다. 나를 위해 2 차원 색인 추가를 테스트 할 때, 잘못된 지오메트리로 인해 오류가 발생한 문서를 삽입 한 다음 주어진 지리 쿼리를 사용하여 찾을 때. 몽고 껍질의 장난감 컬렉션에서 이것을 시험해보고 그것이 효과가 있는지보십시오. MongoDB의 어떤 버전입니까? 다른 인덱스가 있다면 타일 컬렉션에 있습니까? – wdberkeley

답변

0

이것은 내가 앱을 실행할 때마다 실수로 색인을 다시 생성했기 때문에 발생했습니다. 왜냐하면 이렇게하기 전에 매번 삭제해야한다는 것을 알지 못했기 때문입니다.