在Mongoose中更新文档(在特定索引处更新数组属性)

我目前正在练习我的node.js技能,我正在用户的个人资料页面上制作一个top10电影列表。 用户select了十部电影,现在我想将这些电影保存在我的数据库中的用户文档中。 但是,这是行不通的数组仍然是空的(我能够改变“拾取”属性为true)。 谁能告诉我为什么? 这里是服务器端的代码:

router.get('/updateTop10', function (req, res, next) { // the string that I want to add to the db array var movieElement = req.query.movieElement; // the specific index of the array (the position of the movie in the top10 var index = req.query.index; // the user that is currently logged in var user = req.user; User.findOne({'username': user.username }, function (err, user) { // I am able to switch picked to true user.top10.picked = true; // However my array is still empty after I run the code user.top10.top10[index] = movieElement ; user.save(); res.send("SUCCESS") } ) }); 

这是用户文档的结构:

这是用户文档的结构:

请参阅https://github.com/Automattic/mongoose/issues/2654执行此操作

  user.top10.top10.set(index, movieElement);