我有一个临时列和最小临时列。 temp列刚刚连续写入,但是当temp小于minTemp时,minTemp会更新以反映新的低值。我知道下面的代码是错误的, 所以我的专栏是
id and date <- these are my keys
temp <- this is the current temperature
minTemp <- this is the lowest temperature for the day
这是非工作代码,但要了解我想要做什么
var tparams = {
Key: { id: id, date: dayofyear(date)},
TableName: "myTable",
UpdateExpression: "Set minTemp = temp",
ConditionExpression: "temp < minTemp",
ExpressionAttributeValues:{
'temp' : 'minTemp
}
ReturnValues: "UPDATED_NEW"
};
console.log(tparams);
为什么aws文档似乎没有什么帮助呢?
答案 0 :(得分:0)
这是适合我的解决方案。虽然
可能有更好的方法attrNamesMinT["#minTemp"] = "minTemp";
attValuesMinT[":mint"] = temperature;
var mintparams = {
TableName: "myTable",
Key: { id: id, date: dayofyear(date)},
UpdateExpression: "Set #minTemp = :mint",
ConditionExpression: ":mint < #minTemp or attribute_not_exists(#minTemp)",
ExpressionAttributeNames: attrNamesMinT,
ExpressionAttributeValues: attValuesMinT,
ReturnValues: "UPDATED_NEW"
};
console.log(mintparams);
dynamo.updateItem(mintparams, function(err,res){
console.log(err);
});