猫鼬setOnInsert:在查询中使用计算属性

时间:2019-03-21 23:13:11

标签: javascript node.js mongodb mongoose

当我在Mongoose控制台中使用setOnInsert时,我返回我无法在setOnInsert内部使用计算属性,如以下消息所示:

  

SyntaxError:意外令牌[

 findOneAndUpdate:{
     "filter": hour[daySlot].time.timePlot, 
     "$setOnInsert": { hour[daySlot][time]:  update }, // fails to use computed properties
     upsert: true
 }

我的参数是动态的,我需要使用计算的属性。

任何提示都会很棒, 谢谢。

1 个答案:

答案 0 :(得分:2)

您需要在hour[daySlot][time]

周围使用方括号
findOneAndUpdate:{
     "filter": hour[daySlot].time.timePlot, 
     "$setOnInsert": { [hour[daySlot][time]]:  update }, // fails to use computed properties
     upsert: true
 }
相关问题