我想创建一个newEvent
并将其添加到事件数组中。我该如何完成?我正在使用Mongoose来连接我的数据库
事件API
const newEvent = new Event({
title: req.body.title,
start: req.body.start,
end: req.body.end,
allday: req.body.allday,
color: req.body.color,
textcolor: req.body.textcolor,
user: req.user.id
});
事件架构
user: {
type: Schema.Types.ObjectId,
ref: "users"
},
date: {
type: Date,
default: Date.now
},
events: [
{
title: { type: String, required: true },
start: { type: String, required: true },
end: { type: String, required: true },
allday: { type: Boolean },
color: { type: String, required: true },
textcolor: { type: String }
}
]
答案 0 :(得分:0)
const newEvent = new Event({
events: [
{
title: req.body.title,
start: req.body.start,
end: req.body.end,
allday: req.body.allday,
color: req.body.color,
textcolor: req.body.textcolor,
user: req.user.id
}
]
});
newEvent.save().then(event => res.json(event));
}
);