我无法使它正常工作: 我有一个HTML表单:
<form action="/edit" method="POST">
<label for="name">Name:</label>
<input type="text" name="name" value=""> <br><br>
<label for="geojson">GeoJSON:</label>
<input type="text" name="geojson" value=""><br><br>
<input type="submit" value="Add">
</form>
我想在验证之后将输入添加到我的数据库中。名称可以是geojson输入需要是GeoJson点的任何字符串。我是为猫鼬模式编写的:
const pointSchema = new mongoose.Schema({
geojson: [mongoose.Schema.Types.Point]
});
var Point = mongoose.model("Point", pointSchema);
这可以处理来自表单的发帖请求:
app.post('/edit', (req, res) => {
console.log(req.body);
var myData = new Point(req.body);
myData.save()
.then(item => {
console.log("item saved to database");
res.sendFile(__dirname + '/edit.html');
})
.catch((err) => {
console.log("failed");
res.sendFile(__dirname + '/edit.html');
});
});
```
But it wont pass the validation...
Can anyone help me?