如何在嵌套数组中插入新字段

嘿家伙,我可能知道是否有可能在嵌套数组中插入新的字段?

例如像这样的嵌套数组。

"comments" : [ { "name" : "john", "title" : "Facebook", "content" : "LOLOLOLOL", "votes" : { "up" : [ ], "down" : [ ] }, "date" : ISODate("2014-04-24T17:39:49.782Z"), } ], 

是否有可能更新这个嵌套数组与新的领域,所谓的“分数”? 像这样的东西。

  "comments" : [ { "name" : "john", "title" : "Facebook", "content" : "LOLOLOLOL", "votes" : { "up" : [ ], "down" : [ ] }, "date" : ISODate("2014-04-24T17:39:49.782Z"), "scores": 50 } ], 

我已经尝试过这种方法,但我似乎无法使其工作

  // get up vote, down vote to calculate posts.findOne({'comments': { $elemMatch: { permalink: data.permalink } } },function(err, data){ var ups = data.votes.up.length; var downs = data.votes.down.length; var marks = favourite(ups,downs); var scores = { "comments.$.scores":marks } // insert the scores in a nested array as new field. posts.update({'comments': { $elemMatch: { permalink: data.permalink } } },{$set:scores},{upsert:true}, function(err, post) { "use strict"; if (err) console.log(err) }); }); 

 db.yourCollection.update({comments: {$elemMatch:{ name:"john"} } }},{$set:{"comments.$.scores":50}},{multi:true}); 

但是,每个文档只有嵌套数组中的第一个匹配元素才会被修改