1

I have a temp column and a minimum temp column. the temp column is just over written continuously, but when temp is less that minTemp, minTemp is updated to reflect the new low. I know the code below is wrong, so my columns are

id and date <- these are my keys
temp <- this is the current temperature
minTemp <- this is the lowest temperature for the day

And here is the non-working code, but to get an idea of what I am trying to do

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);

Why does it just seem the aws docs are of very little help?

3
  • Expression attribute values must begin with a colon. See docs.aws.amazon.com/amazondynamodb/latest/developerguide/….
    – jarmod
    Commented Jul 7, 2017 at 20:35
  • Yes, i actually got it working after i posted this
    – Messak
    Commented Jul 7, 2017 at 21:00
  • Good to hear but please help others to avoid spending time on this by writing up an answer and marking it as the chosen answer.
    – jarmod
    Commented Jul 7, 2017 at 21:59

1 Answer 1

0

Here is the solution that worked for me. There could very well be better ways of doing it though

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);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.