I have model: where stats.d is current date and t and u are some statistics.
name: string,
stats: [{
d: {type: date, default: moment().format('MM/DD/YYYY')},
t: number,
u: number,
}],
total: number
what I am trying to do is to update, check if date is today if today increment t, if today date is not exist, create or add entry to stats array with current date and starting t point. So that I will have stats by date. Here is what I have tried.
model.findOneAndUpdate({_id:req.params._id}, {$set:{"stats.d": date}, $inc: {total: 1, "stats.t": 1}}, {upsert:true}, function(err, data){
//success
});
But it is not working. I get following error:
can't append to array using string field name: t","code":13048,"ok":0
Could any point out the issue?