in dynamodb i am using a putitem but i want to run a test that if item1 and item2 matches an existing record, i want to do nothing, but if they dont, i want to putitem.
my table
field1 field2 field3
item1 item2 item3
item1b item2b item3b
var item = {myfield1: myfield1, myfield2: myfield2, myfield3: myfield3}
So if
conditionexpression: myfield1 != item1 and myfield2 != item2
i want to
dynamo.putitem…
I had thought it this could be done without a query
i tried using
ConditionExpression: “attribute_not_exists(field1) AND attribute_not_exists(field2)”
but didn’t see the results i want
Related discussions:
You need to make the condition with variables and then use conditionattributevalues to set the values of those variables. You don’t indicate which language you’re using.
Please post your actual code.
In your PutItem parameters you have to specify a key.
Your conditions will only check against that key.
You cannot do something like ‘write Item1 if Field2 does not exist in Item2’. You can only do ‘Write Item1 if Field1 does not exist in Item1’
OK, so i switched to an update item, here is a very simplified version of my code. Let me explain what is going on. So i have a rules table that has
description min max
Temperature 32 100
Pressure 20 36
Then I have a trigger on my receiving table that checks if the (alertTest)values are within the (rules table)min and (rules table)max. If the values fall outside of the range, they are inserted into my alerts table
var updateExpressions =;
updateExpressions.push(“#data”+counter+“=:data”+counter+“, #date”+ counter +" = :date"+ counter);
attrNames[“#data”+ counter] = “data”;
attValues[“:data”+ counter] = data;
attrNames[“#date”+ counter] = “date”;
attValues[“:date”+ counter] = date;
counter++;
then further down
if (alertTest < min || alertTest > max){
var loadparamsP = {
TableName: “mytable”,
Key: { sensor: sensor, custID: custID},
ExpressionAttributeNames:attrNames,
ExpressionAttributeValues:attValues,
UpdateExpression:"SET "+ updateExpressions,
ReturnValues: “UPDATED_NEW”
};
dynamo.updateItem(loadparamsP, function(err,res){
console.log(res + “res”);
if (err)
//throw (err);
callback(err)
else{
callback(null, ‘Data inserted’);
}
});
}
The problem is the description field is not a key, sensor and custID are, so there could be a pressure and temp alert, but only one is being entered
Ok, after everything, i figured it would just be much easier to modify my table