[英]How can I post array in nested object on Postman/form-data?
我想将loc数据发布在postman / form-data中,而没有application / json头。
{
"text": "abcd",
"loc": {
"type": "Point",
"coordinates": [-80, 25]
}
"img": multipart
}
当我在邮递员/表单数据中对此进行整理时
loc.coordinates [0]:-80 loc.coordinates [1]:25文本:... img:...
loc.coordinates不返回任何内容,请参见下文。
{
"data": {
"text": "test",
"tags": [
"testtest"
],
"_id": "5b9e1462c1f13a0fe0912933",
"img": "https://seoul-image-server.s3.cp.ap-northeast-2.amazonaws.com/1537086562695.png",
"user": "5b8e4249f9f8184d0c825c6a",
"date": "2018-09-16T08:29:22.791Z",
"__v": 0
}
}
当我在表单数据中感到厌倦时
loc:{“ type”:“ Point”,“ coordinates”:[-80,25]} ...
它返回
"message": "Memo validation failed: loc: Cast to Embedded failed for value \"{\"type\": \"Point\", \"coordinates\": [-80, 25]}\" at path \"loc\""
为什么??
这是我的图式
const geoSchema = new Schema({
type: {
type: String,
default: 'Point'
},
coordinates: {
required: true,
type: [Number]
}
});
const memoSchema = new Schema({
img: {
type: String,
required: true
},
text: {
type: String,
default: ""
},
date: {
type: Date,
default: Date.now
},
tags: {
type: [String],
set: item => {
if(Array.isArray(item)) {
return item.join('')
}
},
defulat: []
},
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true
},
loc: geoSchema
});
memoSchema.index({
loc: '2dsphere'
});
module.exports = mongoose.model('Memo', memoSchema)
您正在发送JSON,这意味着您必须在双引号“ coordinates”中包装一个数组:“ [-80,25]”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.