使用 DynamoDB.DocumentClient 成功进行 transactWrite 后,ItemCollectionMetrics 为空
ItemCollectionMetrics is empty after successful transactWrite using DynamoDB.DocumentClient
我正在对 DynamoDb 执行 transactWrite
(https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#transactWrite-property) 指令并期望返回 ItemCollectionMetrics
(我在请求中指定 ReturnItemCollectionMetrics: 'SIZE'
)。
对象返回为空 {}
,即使在 dynamo 数据库表上发生了更改。
有人对此有想法吗?
代码
const dynamoResponse = await dynamoDbDocumentClient.transactWrite({
TransactItems: [
{
Put: {
TableName: ENV.BLAH_CONTENT_COUNT_MESSAGES_TABLE,
ExpressionAttributeNames : {
'#v' : 'v',
},
ExpressionAttributeValues : {
':v' : blah.v
},
ConditionExpression: '(attribute_exists(blahId) AND #v<>:v) OR attribute_not_exists(blahId)',
Item: {...blahCountMessage}
}
},
{
Update: {
TableName: ENV.BLAH_CONTENT_COUNTS_TABLE,
Key: { id: blahContentCount.id },
ExpressionAttributeNames : {
'#v' : 'v',
'#count' : 'count',
'#contentId': 'contentId'
},
ExpressionAttributeValues : {
':v' : 1,
':count' : deleted ? -1: 1,
':contentId': blahContentCount.contentId,
':defaultNumber': 0
},
ConditionExpression: 'attribute_not_exists(cognitoId)',
UpdateExpression: 'SET #contentId = :contentId, #count = if_not_exists(#count, :defaultNumber) + :count, #v = if_not_exists(#v, :defaultNumber) + :v',
ReturnValuesOnConditionCheckFailure: 'ALL_OLD'
}
}
],
ReturnItemCollectionMetrics: 'SIZE'
}).promise();
输出
console.log(JSON.stringify(dynamoResponse.ItemCollectionMetrics)); // {}
谢谢!
ReturnItemCollectionMetrics:
"Information about item collections, if any, that were affected by the operation. ItemCollectionMetrics is only returned if the request asked for it. If the table does not have any local secondary indexes, this information is not returned in the response."
根据:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ItemCollectionMetrics.html
可能是此事务没有更新任何内容 - 或者您没有 LSI?
另请注意:文档说交易被禁用
"global tables",我不太确定它们是不是指 GSI...但我不是
使用 LSI 这可能也是为什么没有 ItemCollectionMetrics 的原因
返回响应我的交易。
如果更新参数对象以包含 ReturnConsumedCapacity: 'TOTAL'
,则响应对象应如下所示:
[ { TableName: 'table_name',
CapacityUnits: 8,
WriteCapacityUnits: 8 } ] }
我正在对 DynamoDb 执行 transactWrite
(https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#transactWrite-property) 指令并期望返回 ItemCollectionMetrics
(我在请求中指定 ReturnItemCollectionMetrics: 'SIZE'
)。
对象返回为空 {}
,即使在 dynamo 数据库表上发生了更改。
有人对此有想法吗?
代码
const dynamoResponse = await dynamoDbDocumentClient.transactWrite({
TransactItems: [
{
Put: {
TableName: ENV.BLAH_CONTENT_COUNT_MESSAGES_TABLE,
ExpressionAttributeNames : {
'#v' : 'v',
},
ExpressionAttributeValues : {
':v' : blah.v
},
ConditionExpression: '(attribute_exists(blahId) AND #v<>:v) OR attribute_not_exists(blahId)',
Item: {...blahCountMessage}
}
},
{
Update: {
TableName: ENV.BLAH_CONTENT_COUNTS_TABLE,
Key: { id: blahContentCount.id },
ExpressionAttributeNames : {
'#v' : 'v',
'#count' : 'count',
'#contentId': 'contentId'
},
ExpressionAttributeValues : {
':v' : 1,
':count' : deleted ? -1: 1,
':contentId': blahContentCount.contentId,
':defaultNumber': 0
},
ConditionExpression: 'attribute_not_exists(cognitoId)',
UpdateExpression: 'SET #contentId = :contentId, #count = if_not_exists(#count, :defaultNumber) + :count, #v = if_not_exists(#v, :defaultNumber) + :v',
ReturnValuesOnConditionCheckFailure: 'ALL_OLD'
}
}
],
ReturnItemCollectionMetrics: 'SIZE'
}).promise();
输出
console.log(JSON.stringify(dynamoResponse.ItemCollectionMetrics)); // {}
谢谢!
ReturnItemCollectionMetrics:
"Information about item collections, if any, that were affected by the operation. ItemCollectionMetrics is only returned if the request asked for it. If the table does not have any local secondary indexes, this information is not returned in the response."
根据:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ItemCollectionMetrics.html
可能是此事务没有更新任何内容 - 或者您没有 LSI?
另请注意:文档说交易被禁用 "global tables",我不太确定它们是不是指 GSI...但我不是 使用 LSI 这可能也是为什么没有 ItemCollectionMetrics 的原因 返回响应我的交易。
如果更新参数对象以包含 ReturnConsumedCapacity: 'TOTAL'
,则响应对象应如下所示:
[ { TableName: 'table_name',
CapacityUnits: 8,
WriteCapacityUnits: 8 } ] }