mean-stack - 使用 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}`
请建议我可能会在哪里搞砸。
解决方案
我想我已经想通了......
我尝试稍微更改一下参数,并能够获得预期的结果。
我试过了:
curl http://localhost:3000/posts -i -X POST -d "title=Bigdadi Rules Posts&link=http://www.foo.com&upvotes=2"
有用!!!
推荐阅读
- solidity - 在 remix IDE 中编译我的代码时遇到问题
- javascript - Javascript 小部件性能:获取静态 HTML/JS 文件 - 与 DOM 操作
- python - 将列表拆分为 nx 长度矩阵
- spring-boot - 为什么我的应用程序调用一次但插入数据两次?
- kubernetes - AWS lambda 和 IAM 网络策略
- google-sheets - 如何使用 Google 表格中的公式计算特定列的行数
- javascript - 我怎样才能使这个“开始”按钮在这个标题下方居中?
- javascript - 根据第二个数组项值删除数组重复项
- android - Android RecyclerView - 很长的图像在仍在使用空间时未显示/变黑
- swift - 如何使用 SwiftUI 在客户端访问 Firebase 自定义声明?