Hiii, I have a MEAN stack application that make use of a mongoose model defined as below:
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
}
]
});
I want to generate a document like the following:
{
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,
}
}
I can't generate a document when using the following Express JS code:
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
});
After performing the above operations, the result that I get is as follows:
"_id": ObjectId('57b6eefd2b494e802ba146d8'),
"appt_date": "12/20/2014",
"details": [],
"__v": 0
I am not able to push any data to the "details" array. What I am in need is a single date entry (appt_date), multiple details (details array). Please help to solve this out.
Thank You.