I am trying to update the month and the year fields in the incomes array but the command that I am using is substituting the object in the array for the updated object value(s). Note that the updated object has fewer key/value(s) than the original one.
{
"_id" : 12j3k123132,
"username" : "Alex",
"password" : "12345",
"email" : "a@ass",
"incomes" : [
{
"incomeId" : aisjdoaijfa,
"month" : 10,
"year" : 2017,
"value" : 100.57,
"description" : "car wash"
}
],
"expenses" : [ ]
}
I am running the follow command, where updateInfo contains all the information that will be updated
incomeSearch.update({ _id: 12j3k123132), "incomes.incomeId": incomeId.incomeId }, {$set: {"incomes.$": updateInfo}}, (err, updateResult) => {
if (err){
res.status(500).send({error: `An error occurred. ${err}`});
}
res.status(200).send({msg: `Income updated`, result: updateResult});
});