i have a mongoose model something like
module.exports = mongoose.model('ContactBirthday', {
email: {
type: String,
unique: true
},
birthday: {
"1": {
"1": [
{
"firstName": String,
}
],
"2": [
{
"firstName": String,
}
]
}
}
}
i want to push a value in birthday.1.2 . I have the value of 1 and 2 in variables bMonth and bDate , and using the following code to push , but somehow only email is inserted
var bMonth = req.body.contact.birthday.month;
var bDate = req.body.contact.birthday.date;
ContactBirthday.findOneAndUpdate({
email: result.message.email
}, {
$push: {
birthday: {
bMonth: {
bDate: {
"firstName": req.body.contact.birthday.firstName,
"_id": data[0].contacts[data[0].contacts.length - 1]._id
}
}
}
}
}, {
upsert: true
}, function (err, result) {
if (err)
return res.send(500, {
error: err
});
else
res.sendStatus(200);
});
bDate: { "firstName": "value" }is an object with key bDate! It's not actually{ 12/11/2015: { ...Also don't do that kind of nasty nasting!Datetype in it! :) Just make it a field inside the User schema, if you have one