I am trying to do something like this:
Industry.findOne({_id: id}).exec(function(err, industry){
industry.stats = _.extend(industry.stats, stats); //.......(1)
industry.save(function(err) {
// nothing is saved
});
});
The console.log of industry.stats in (1) is
[{ stat_id: 545080c8e4e88b1d5a7a6d1b}{ stat_id: 54526ca6b294096d33ca6b36 }]
This is not working, apparently the industry.stats is not an object array and misses a comma in between the two objects. (am I stating this correctly?)
If I assign industry.stats directly like this
[{stat_id: 545080c8e4e88b1d5a7a6d1b}, {stat_id: 54526ca6b294096d33ca6b36}]
Then it's working. Is there something I need to do to convert (1) to an object array first? I tried lean() and toObject()...etc but I got no luck. Am I missing something?