0
所以這應該是簡單的...追加或建立StringSet如果它不存在
我想追加一個字符串到StringSet在DynamoDB如果存在的話,或者如果它不創造StringSet財產並且設定價值。如果我們可以用一個空數組初始化創建StringSet,那很好,但是我們不能。
這是我到目前爲止有:
const companiesTable = 'companies';
dynamodb.updateItem({
TableName: companiesTable,
Key: {
id: {
S: company.id
}
},
UpdateExpression: 'ADD socialAccounts = list_append(socialAccount, :socialAccountId)',
ExpressionAttributeValues: {
':socialAccountId': {
'S': [socialAccountId]
}
},
ReturnValues: "ALL_NEW"
}, function(err, companyData) {
if (err) return cb({ error: true, message: err });
const response = {
error: false,
message: 'Social account created',
socialAccountData
};
cb(response);
});
我也試過......
UpdateExpression: 'SET socialAccounts = list_append(socialAccounts, :socialAccountId)',
ExpressionAttributeValues: {
':socialAccountId': {
S: socialAccountId
}
},
和...
UpdateExpression: 'ADD socialAccounts = :socialAccountId',
ExpressionAttributeValues: {
':socialAccountId': {
S: socialAccountId
}
},
和...
UpdateExpression: 'SET socialAccounts = [:socialAccountId]',
ExpressionAttributeValues: {
':socialAccountId': socialAccountId
},
和...
UpdateExpression: 'ADD socialAccounts = :socialAccountId',
ExpressionAttributeValues: {
':socialAccountId': socialAccountId
},
其中關於以上的其他變化。我是否愚蠢? DynamoDB不能簡單地寫入/更新數組類型字段嗎?在嘗試添加或設置該字段之前,我是否真的必須首先查找該項目以查看它是否具有該字段,因爲我無法用空數組實例化該字段?
完美,這解決了我的問題! –