【发布时间】:2014-11-29 23:34:49
【问题描述】:
我有一个 JSON 对象,我想创建一个使用 mongoose 的模式
{ ProjectName: 'asdf',
Embargo: 'Yes',
Angle: '1',
Facts: '[{"count":1,"fact":"dsafdsaf","content":"dsafdsaf"}, {"count":3,"fact":"dsafdsaf","content":"dsafdsaf" } , {"count":2,"fact":"dsafdsaf","content":"dsafdsaf"}]',
About: '<p>Anthony Bodin </p>',
EditorNote: 'No',
OrderId: 'tok_14kGRO2Jju1nvjb47YF9jQTJ',
Payment: 'Paid' }
我的问题是 Facts 元素将包含对象数组,我不太确定如何将其保存到数据库中 这是我现在拥有的架构
var ArticleSchema = new mongoose.Schema({
userId: {
type: String,
default: ''
},
userEmail: {
type: String,
default: ''
},
article: {
date: {
type: Date,
default: Date()
},
ProjectName: {
type: String,
default: ''
},
Embargo: {
type: String,
default: true
},
Angle: {
type: String,
default: ''
},
Facts: {
type:Array
},
About: {
type:String,
default:''
},
EditorNote: {
type:String,
default:''
},
Payment: {
type: String,
default: 'Not Paid'
},
OrderId: {
type:String,
default:''
}
}
});
将数据保存为数组是保存 Facts 元素的正确方法吗?
【问题讨论】:
标签: arrays json node.js mongodb mongoose