스키마의 mongoose geojson, "지역 키를 추출할 수 없습니다" 오류 (mongoose geojson in schema, "Can't extract geo keys" error)


문제 설명

스키마의 mongoose geojson, "지역 키를 추출할 수 없습니다" 오류 (mongoose geojson in schema, "Can't extract geo keys" error)

정의된 스키마가 있는 mongodb 컬렉션이 있으며 위도/경도 좌표를 포함하도록 이 스키마를 업데이트했습니다.

이전 버전:

var schema = mongoose.Schema({
    id: String,
    name: String,
    address: String,
    city: String,
    zip: String,
    country: String,
    phoneNumber: String,
    mobile: String,
    website: String,
    email: String,
});

새 버전

var schema = mongoose.Schema({
    id: String,
    name: String,
    address: String,
    city: String,
    zip: String,
    country: String,
    phoneNumber: String,
    mobile: String,
    website: String,
    email: String,
    location: GeoJSON.Point
});

schema.index({ location: '2dsphere' });

GEOJSON.Pointmongoose‑geojson‑schema에서 가져온 것으로 다음과 같습니다.

GeoJSON.Point = {
  'type'     : { type: String, default: "Point" },
  coordinates: [
    {type: "Number"}
  ]
}

컬렉션에는 location 속성.

분명히 지금 일어나는 일은 mongodb가 { 좌표: [], 유형: "Point" }를 기본값으로 사용한다는 것입니다. 기존 문서에서 다음과 같은 오류가 발생합니다.

 MongoError: Can't extract geo keys: { _id: ObjectId('5637ea3ca5b2613f37d826f6'), ...
 Point must only contain numeric elements 

스키마에서 기본값을 지정하는 방법을 살펴보았지만 값을 null(GeoJSON.Point 데이터 유형의 경우).

또한 시도했습니다

db.collection.update({},{$set:{location:null},{multi:true})

하지만 그것도 도움이 되지 않는 것 같습니다.

위치의 색인 때문인가요?


참조 솔루션

방법 1:

I think you need to upgrade GeoJSON.Point to a sub document with a proper schema:

GeoJSON.Point = new mongoose.Schema({
  'type'     : { type: String, default: "Point" },
  coordinates: [ { type: "Number" } ]
});

Combined with the minimize option, which it enabled by default, this will make Mongoose only save the location property if it is actually set.

방법 2:

I would suggest you to not use GeoJSON.Point as a schema type. Just use mixed object type and everything will work properly.

location: Schema.Types.Mixed

(by Joris MansrobertklepKarlen)

참조 문서

  1. mongoose geojson in schema, "Can't extract geo keys" error (CC BY‑SA 2.5/3.0/4.0)

#geojson #Mongoose #mongoDB #node.js






관련 질문

Geodjango GeoJSON 직렬 변환기 기하학은 항상 'null'입니다. (Geodjango GeoJSON Serializer geometry always 'null')

전단지에서 레이어 켜기/끄기(더 복잡한 시나리오) (Toggle layers on and off in Leaflet (more complex scenario))

RethinkDB r.polygon() - GeoJSON LinearRing에는 최소 4개의 위치가 있어야 합니까? (RethinkDB r.polygon() - GeoJSON LinearRing must have at least four positions?)

Leaflet : GeoJSON 속성에서 GeoJSON 레이어 설정 아이콘 (Leaflet : setting icon for GeoJSON layer from GeoJSON property)

'GeoJsonLayer' 기호를 확인할 수 없습니다. (Cannot resolve symbol 'GeoJsonLayer ')

스키마의 mongoose geojson, "지역 키를 추출할 수 없습니다" 오류 (mongoose geojson in schema, "Can't extract geo keys" error)

Android Google 지도는 GeoJSON을 사용하여 마커를 설정합니다. (Android Google Maps set marker using GeoJSON)

GraphQl로 geojson 포인트를 쿼리하는 방법은 무엇입니까? (How to query a geojson point with GraphQl?)

geojson 포인트 데이터 마커가 전단지 맵에서 클러스터링되지 않습니다. (The geojson point data markers are not clustering in leaflet map)

전단지 geoJSON.onEachFeature는 함수가 아닌가요? (leaflet geoJSON.onEachFeature is not a function?)

Folium에서 특정 국가 강조 표시 (Highlight one specific country in Folium)

RGeo 및 Geojson으로 면적 계산 (Calculating area with RGeo and Geojson)







코멘트