geocoder.geocode
콜백 에서 해당 필드를 설정 하므로 this
더 이상 위치 인스턴스를 참조하지 않습니다.
대신 다음과 같이하십시오.
LocationSchema.pre('save', function(next) {
var doc = this;
geocoder.geocode(this.address, function ( err, data ) {
if(data && data.status == 'OK'){
doc.lat = data.results[0].geometry.location.lat;
doc.lng = data.results[0].geometry.location.lng;
}
next();
});
});
출처
https://stackoverflow.com/questions/22079879