【问题标题】:How to add data into postman如何将数据添加到邮递员
【发布时间】:2017-06-10 08:50:48
【问题描述】:

如果我想在下面的架构中添加一些数据:

'use strict';

var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var notificationsSchema = new mongoose.Schema({
    notifyMessage                   : { 
            title                       : { type: String },
            des                         : { type: String }
        },
        notifier                        : { type: String },
        recipient                       : [{
            id                          : { type: String },
            status                      : {type:String,trim:true,enum:['read','unread']}
        }]
});

module.exports = mongoose.model('notification_tracker', notificationsSchema);

我试过这样:

但结果是这样的..

【问题讨论】:

  • 请尝试以 JSON 格式发送原始数据。选择单选按钮“原始”。

标签: javascript postman


【解决方案1】:

选择 raw 单选按钮并确保将其设置为 JSON(application/json) 然后像这样粘贴或添加您的 JSON 对象

{
  notifyMessage: {
    title: "",
    des: ""
  },
  notifier: "",
  recipient: [{
    id: "",
    status:""
  }, {
    id: "",
    status:""
  }]
}

使用这种格式

【讨论】:

  • 收件人?
  • 同样的事情,你可以在 notifyMessage 之后添加另一个对象。
  • @swatikiran 我已经更新了我的答案。您可以使用我添加的格式,然后根据您想要的值进行更新
  • recipient is array... 起初我收到错误说'bad string' ... SyntaxError: Unexpected token n
  • @swatikiran 哎呀。我已经更新了答案。您还可以查看json.org/example.html 以查看 JSON 的一些示例格式。
【解决方案2】:

我认为您可以选择“原始”选项而不是 form-urlencoded,然后只需输入您的 json 代码:

    notifyMessage : { 
            title : something,
            des : something
        }}
...etc

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 1970-01-01
    • 2019-05-08
    • 2022-01-21
    • 1970-01-01
    • 2020-01-10
    • 2021-02-15
    • 1970-01-01
    • 2020-06-09
    相关资源
    最近更新 更多