【发布时间】:2020-08-26 20:01:33
【问题描述】:
当我尝试这样做时,我会发布其余的数据,但数组仍然为空
我的 Schma 看起来像这样
const mongoose = require('mongoose');
const DocumentSchema = mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
},
dateCreated: String,
title: String,
// ID of the users that created the document
creatorId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'users',
},
comment: [{ title: String, detail: String }]
});
module.exports = mongoose.model('myDocument', DocumentSchema);
我在 postman 中的 Post 脚本是这样的
{
"label":"Got More data",
"linkUrl":"www.google.com",
"title":"test 14",
"comment":[
{
"title":"hello",
"detail":"some detail"
}]
}
当我得到我更新的数据时,它看起来像这样
{
"_id": "5eb91c0e35eecb369696b9c5",
"title": "test 14",
"creatorId": "5d8856e5903a260588b77c30",
"user": "5d8856e5903a260588b77c30",
"dateCreated": "Mon May 11 2020 10:34:06 GMT+0100 (British Summer Time)",
"comment": [],
"__v": 0
}
我尝试过的其他事情
我已尝试根据 Stack Overflow How to define object in array in Mongoose schema correctly with 2d geo index 上的这篇文章更改架构定义
到这里
comment : [{
title : String,
detail : String
}]
还有这种方法
comment : {
"title":"A title",
"detail": "some random comment"
}
但我仍然得到一个空白数组
【问题讨论】:
标签: mongodb postman mongoose-schema