首页 > 解决方案 > 使用 cURL 测试 REST 路由 - 数据不保存

问题描述

我正在浏览Open REST Routes中的教程,但我现在坚持将数据发布到 mongodb 帖子集合。

当我 cURL 它执行时没有错误,但我的标题和链接没有保存,upvotes 默认为 0,如架构中定义的那样。

我的帖子架构是:

var mongoose = require('mongoose');
var PostSchema = new mongoose.Schema({
   title: String,
   link: String,
   upvotes: {type: Number, default: 0},
   comments: [{type: mongoose.Schema.Types.ObjectId, ref: 'Comment'}]
});
mongoose.model('Post', PostSchema);

我得到以下结果:

curl http://localhost:3000/posts -d '{"title":"Go Bigdadi! Nicely done!!!","link":"http://www.foo.com","upvotes":2}'
{"upvotes":0,"comments":[],"_id":"5b740c875bdf6a326c677cd3","__v":0}`

请建议我可能会在哪里搞砸。

标签: mean-stack

解决方案


我想我已经想通了......

我尝试稍微更改一下参数,并能够获得预期的结果。

我试过了:

curl http://localhost:3000/posts -i -X POST -d "title=Bigdadi Rules Posts&link=http://www.foo.com&upvotes=2"

有用!!!


推荐阅读