在Meteor中突然出现错误“Key $必须以'$'开头”

时间:2017-09-29 21:28:56

标签: javascript mongodb meteor minimongo

我能够像这样进行$addToSet操作:

return Calls.update({ _id: callId }, {
    $addToSet: {
      units: {
        unit: callSign,
        currentStatus: "AS",
        statusColor: "yellow",
        textColor: "black",
        assignable: false,
        assignedBy: Meteor.users.findOne(this.userId).username,
        assignedOn: new Date(),
      },
    }
  }
);

但是,当我尝试像这样更新这个集合时:

return Calls.update({ _id: callId, "units.unit": callSign }, {
    $set: {
      "units.$.statusColor": "#74eeea",
      "units.$.textColor": "black",
      "units.$.currentStatus": "ER",
      "units.$.enrouteBy": Meteor.users.findOne(this.userId).username,
      "units.$.enrouteOn": new Date(),
    }
  }, {
    upsert: true
  }
);

我收到此错误:

  

调用方法'call.enrouteUnit'时出现异常MinimongoError:Key $不能以'$'开头

我知道这是来自$set我使用"<array>.$.<key>: <value>格式的行(如果不是全部的话)。

到现在为止一直在努力,所以不确定发生了什么。

更新:问题似乎与我使用upsert有关。不知道为什么它突然决定这是一个问题,但似乎是。继续看它。

0 个答案:

没有答案