我们如何基于索引(而不是基于主键和范围键)更新dynamodb表。
我有一个按名称创建的索引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
});
您无法写入 GSI。
您唯一的选择是首先从 GSI 读取,获取作为您的键的属性值(它们始终投影到索引上,请参阅GSI.预测 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Projections),然后将数据写回到表中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)