我尝试为 geojson 创建架构但在坐标的语法上遇到了一些问题。
这是我当前的代码:
var DataSchema = new Schema({
properties: {
title: { type: String, required: true },
description: { type: String, required: true },
date: { type:Date, default:Date.now }
},
geometry: {
coordinates: []
}
});
我尝试使用 []
(空数组),它会创建 ''
和 [Number,Number]
但它不起作用.
我的问题是:我必须如何构建我的架构才能得到结果
coordinates: [ 3.43434343, 5.543434343 ]
不用引号,这样可以吗?
快速路线
app.post('/mountain_rescue', function (req, res){
new rescueData({properties:{title: req.body.title, description: req.body.description},geometry:{
coordinates:req.body.coordinates}}).save(function (e, result) {
console.log(result);
});
res.redirect('/mountain_rescue');
});
查看
<div id="AddingPanel">
<form method="post" action="mountain_rescue" >
Title:<input type="text" name="title">
Description:<textarea type="text" name="description"></textarea>
Coordinates:<input type="text" name="coordinates">
<button type="submit">Add</button>
</form>
最佳答案
GeoJSON 字段必须包含几何类型作为字符串。所以必须像下面这样定义 GeoJSON 字段;
geometry: { type: { type: String }, coordinates: [Number] }
或者如果你想定义一个默认值,你可以使用下面的行;
geometry: { type: { type: String, default:'Point' }, coordinates: [Number] }
祝你好运……
关于javascript - geoJson 坐标的 Mongoose 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28749471/