项目研发过程中需要用到根据条件(两个字段进行比较),符合条件然后修改字段值。
几经摸索查找得以实现,现记录如下:
db.initUmsTaskInfo.update({"umsCode":"50","$where": "this.gatewaySendInstructionFlag > this.sensorInitFinishedFlag + 20"},{"$inc":{"gatewaySendInstructionFlag":8}})
其中 umsCode、gatewaySendInstructionFlag、sensorInitFinishedFlag均为字段名。
另外需要强调的是 $where 条件表达式中的值为字符串,并且”this.“ 不能少。