I need to insert a document if the primary key doesn't exist. I have tried to solve this using conditionExpression but it seems to fail.
const primaryKey = "4234241";
const tableSpec = {
TableName: 'tableName',
Item: params,
ConditionExpression: '#primaryId <> :primaryId',
ExpressionAttributeNames: {'#primaryId': 'primaryId'},
ExpressionAttributeValues: {
':primaryValue': primaryValue
}
};
var docClient = new AWS.DynamoDB.DocumentClient();
docClient.put(tableSpec, function (err, data) {
if (err) {
console.log(err);
}
});
"ConditionalCheckFailedException: The conditional request failed" is the output of the console.log statement.