我能够像这样进行$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
有关。不知道为什么它突然决定这是一个问题,但似乎是。继续看它。