嗨,我有一个使用MEAN技术栈的应用程序,其中使用了下面定义的mongoose模型:
appointment.js
我想生成类似以下的文档:
执行完以上操作后,我得到的结果如下:
我无法向"details"数组中推送任何数据。我需要的是一个单一的日期条目(appt_date)和多个细节(details数组)。请帮忙解决这个问题。
谢谢。
appointment.js
var mongoose = require('mongoose');
module.exports = mongoose.model('Appointment', {
appt_date: String,
details: [ {
appt_time: String,
patient_id : String,
patient_name : String,
contact_no: String,
doctor_name : String,
purpose : String
}
]
});
我想生成类似以下的文档:
{
appt_date: 13/13/2013,
details: [
{
appt_time: 09:00 AM,
patient_id: 2015/2016,
patient_name: David John,
contact_no: 8965741234,
doctor_name: Albert ,
purpose: Consultation,
}
}
当我使用以下的Express JS代码时,无法生成文档:
var Appointment = require('../../models/appointment');
var appointments = new Appointment ({ "appt_date" : req.body.date});
appointments.save();
Appointment.update({ appt_date: req.body.date},
{
$push: {
'details': {
appt_time:"09:00 AM",
patient_id:"2015/2016",
patient_name:"Wilfred",
contact_no:"8965741234",
doctor_name: "Albert",
purpose: "Consultation"
}
}
},
{
upsert:true
});
执行完以上操作后,我得到的结果如下:
"_id": ObjectId('57b6eefd2b494e802ba146d8'),
"appt_date": "12/20/2014",
"details": [],
"__v": 0
我无法向"details"数组中推送任何数据。我需要的是一个单一的日期条目(appt_date)和多个细节(details数组)。请帮忙解决这个问题。
谢谢。