新手問題和混亂,因爲我正在學習Hapi/Mongoose/Mongo。GeoJSON/mongoose-geojson-schema /介紹混淆
負責自己有想簡單地創建一個模型/對象包含文本和地理位置點(LAT & LON),並且可以使用所提供的電流LAT & LON
檢索數據庫這些對象試圖建立一個模式使用貓鼬-以GeoJSON-架構包
"mongoose": "^4.11.1", "mongoose-geojson-schema": "^2.1.2"
型號:
const GeoJSON = require('mongoose-geojson-schema');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Point = mongoose.Schema.Types.Point
const postModel = new Schema({
_owner: { type: String, ref: 'User' },
text: { type: String },
loc: Point
});
創建帖子:
let post = new Post();
post._owner = req.payload.user_id;
post.text = req.payload.text;
var point = new GeoJSON({
point: {
type: "Point",
coordinates: [req.payload.lat, req.payload.lon]
}
})
post.loc = point
保持在日誌中發現了錯誤GeoJSON is not a constructor
。試過不同的變化,並得到了其他的錯誤,如loc: Cast to Point failed for value "{ type: 'Point', coordinates: [ '39.0525909', '-94.5924078' ] }" at path "loc"
謝謝,我最終也是這樣的! – ndyr