I have this DynamoDB table
TableName: MyTable
string HashKey: Id,
string RangeKey: createTime
Other attributes
string partId
string carNum
string partId_carNum
Local_secondary_index : partId, projection_type = "ALL"
Local_secondary_index : partId_carNum, projection_type = "ALL"
I am trying to achieve post with unique combination of Id and partId_carNum. But the conditionExpression is not working. I am seeing duplicate entries in the table. What is wrong in my code?
Here is how my typeScript looks
Below is an example of an item
{
"Id" : "000001823841",
"partId" : "1",
"carNum" : "car",
"createTime" : "124232353"
}
const params: PutItemInput = {
TableName: MyTable,
Item: item,
ConditionExpression: 'Id <> :f AND partId_carNum <> :g',
ExpressionAttributeValues: {
':f': { 'S': '000001823841' },
':g': { 'S': '1#car' }
}
};
return await new DynamoDB()
.putItem(params)
.promise()
.then(() => {
console.log(`SUCCESS: Event with ID inserted`);
})
.catch(err => {
console.error(`FAILED to write event to ${params.TableName}. with Error: ${err}`);
});