【发布时间】:2019-01-22 06:47:47
【问题描述】:
我有一个猫鼬模型
const clientSchema = mongoose.Schema({
Created: {
type: String
},
kundnr: {
type: String,
unique: true,
required: true
},
namn: {
type: String
},
adress: {
gata: String,
postkod: Number,
stad: String
},
kontakt: {
email: String,
telefon: Number,
},
company: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Company'
},
notering: [{
type: String,
}],
lan: [{
type: String
}]
}, {
timestamps: true
});
module.exports = mongoose.model('Client', clientSchema);
`
然后就是函数
newClient.kundnr = req.body.kundnr;
newClient.namn = req.body.namn;
newClient.adress.gata = req.body.gata;
newClient.adress.postkod = req.body.postkod;
newClient.adress.stad = req.body.stad;
newClient.kontakt.email = req.body.email;
newClient.kontakt.telefon = req.body.telefon;
newClient.notering = req.body.notering;
const save = await newClient.save()
//redirect
res.redirect('/newClient');
当我保存时,我想将“注意”推送到数组中,这很有效。但在数组中,我想同时查看字符串 + 创建/编辑的日期。
所以当我查看数组时,我在位置 0 看到两个不同的东西,字符串和日期。
不知道该怎么做,也许甚至不应该使用数组,而应该使用对象?
【问题讨论】:
-
没人有答案吗?就像你发布一篇博文一样,你会看到日期、作者和帖子..
标签: arrays mongodb express mongoose mongoose-schema