[英]Dynamodb put item overwrites the old one
I have table defined as follows: 我的表定义如下:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "deviceId"
AttributeType: "S"
KeySchema:
- AttributeName: "deviceId"
KeyType: "HASH"
I call the following code to add a new entry 我调用以下代码以添加新条目
this.client = new AWS.DynamoDB.DocumentClient();
public saveItem(entry): Promise<any> {
let dbEntry = Database.decorateWithStandardFields(JSON.parse(entry));
const params = {
TableName: eventLogTable,
Item: dbEntry
};
console.log('save this to db', params);
return this.client.put(params).promise();
}
the 2 different entries are 2个不同的条目是
{ TableName: 'sls-basic-operations-items-dev',
Item:
{
status: 'changed',
deviceId: 'device12345',
wkStation: 'xyz',
Timestamp: 1561050389,
TTL: 1561136789
}
}
the second one is only different for Timestamp and TTL values. 第二个仅时间戳和TTL值不同。
{ TableName: 'sls-basic-operations-items-dev',
Item:
{
status: 'changed',
deviceId: 'device12345',
wkStation: 'xyz',
Timestamp: 1561050417,
TTL: 1561136817
}
}
with this code, I always end up with one item and it is the last one. 有了这段代码,我总是得到一个项目,而它是最后一个。
What is wrong with this code? 此代码有什么问题?
Your table only has a hash key, so there can only ever be one record with a given deviceID. 您的表只有一个哈希键,因此只能有一条具有给定deviceID的记录。
Seems like you might want to define timestamp as a sort key. 似乎您可能想将时间戳定义为排序键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.