gpt4 book ai didi

node.js - 在 Insomnia 中发送 JSON 对象字段

转载 作者:太空宇宙 更新时间:2023-11-04 01:46:16 26 4
gpt4 key购买 nike

我正在尝试在我拥有的字段之一内发送一个 JSON 对象,以便将其存储在 MongoDB 中(使用 Mongoose Schema)。现在我面临服务器端 JSON 解析错误。

这就是我要发送的内容

{
"text":"N1y",
"localId":"123",
"type": "media",
"attachments": {
url:"Test.jpg",
publicId:"123"
}
}

我的 Moongose 架构

const messageSchema = mongoose.Schema({
createdAt: {
type: String,
default: new Date()
},
chatId: {
type: String,
required: true
},
localId: {
type: String,
required: true
},
text: {
type: String,
required: true
},
authorId: {
type: String,
required: true
},
type: {
type: String,
default: 'text'
},
attachments: {},
style: {
type: String,
default: 'normal'
}

将 Node.JS 与 Express 结合使用。

最佳答案

在架构中将附件类型更新为对象并以不正确的 json 请求对象。

{ “文本”:“N1y”, “本地ID”:“123”, “类型”:“媒体”, “附件”:{ "url": "测试.jpg", “publicId”:“123” }}

架构

attachments: {
type : Object
},

attachments: {
url: {
type: String
},
publicId: {
type: String
},
}

关于node.js - 在 Insomnia 中发送 JSON 对象字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51358396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com