我正在经历看起来像是一个错误或完全疏忽的事情。我有一个mongoose模式,模型和如下所述定义的模型的新实例。当我尝试创建一个新事件并保存它时,其中一个字段被完全忽略。当我在mongodb中查看文档时,enddate字段不存在。我的第二个问题是在我的req.user(通过护照登录系统创建)中,我有一个看起来像这样的对象:
req.user: { name:
{ firstname: 'John',
lastname: 'Smith',
fullname: 'John Smith' },
_id: 5a500b3f0777ab3b28422ad2,
username: 'XXX', etc...}}
问题:
我的活动架构
var EventSchema = new mongoose.Schema({
// _id : mongoose.Schema.ObjectId,
type: String,
name : String,
owner : {fullname: String, username: String},
startdate : String,
enddate : String,
completeddate : String
});
我创建并保存新活动的代码部分:
var newEvent = new EventModel({
// event_id: "5a482302a469a068edc004e3",
type: req.body.eventtype,
name: req.body.eventname,
owner : {fullname: req.user.name.firstname + " " + req.user.name.lastname, username: req.user.username},
startdate: req.body.startdate,
enddate : req.body.enddate,
completeddate : ""
});
newEvent.save(function (err, result) {
if (err) {
console.log("ERROR CREATING EVENT");
console.log(err.name + ": " + err.message);
res.response(err.name + ": " + err.message);
} else {
console.log("SUCCESSFUL EVENT ADDITION");
callback(result)
}
});