如何根据索引更新dynamodb表(不基于primary has和range键)
我有一个名称key_id-index
创建的索引
哈希值为asset_id
,范围为hit_id
。
我想根据key_id-index
更新表格,因为在更新时我不会知道这些内容。
var paramsu = {
TableName: 'asset',
//IndexName: 'key_id-index',
Key: { // The primary key of the item (a map of attribute name to AttributeValue)
asset_id: { S: 'a' },
hit_id: { S: 'h' }
// more attributes...
},
AttributeUpdates: { // The attributes to update (map of attribute name to AttributeValueUpdate)
key_id: {
Action: 'PUT', // PUT (replace)
// ADD (adds to number or set)
// DELETE (delete attribute or remove from set)
Value: { S: 'updated1' }
}
// more attribute updates: ...
},
ReturnValues: 'NONE', // optional (NONE | ALL_OLD | UPDATED_OLD | ALL_NEW | UPDATED_NEW)
ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES)
ReturnItemCollectionMetrics: 'NONE' // optional (NONE | SIZE)
};
db.updateItem(paramsu, function(err, data) {
if (err) console.log(err); // an error occurred
else console.log(data); // successful response
});