β

Answer by zangw for In meteorjs with mongodb how d

User zangw - Stack Overflow 62 阅读

There is an array within an array in your data, there is no easy way to reference the nested sub-array quizScore unless you know the position in this sub-array you want to update.

You can access the outer array courseList through $ , and to access the inner array quizScore through position. Here is one sample code to update the first element of quizeScore matching courseId through using $set and $inc in one update statement.

Meteor.users.update(
          {_id: Meteor.userId(), 
          'courseList.courseId': courseId}, 
          {$set: {'courseList.$.quizScore.0.ans': selectedAns}, 
           $inc: {'courseList.$.quizScore.0.retry': 1}
          });
作者:User zangw - Stack Overflow
most recent 30 from stackoverflow.com
原文地址:Answer by zangw for In meteorjs with mongodb how d, 感谢原作者分享。

发表评论