2016-08-18 2 views
0

存在しないのであれば、これは簡単であるべきまたはStringSetを作成...追加それは

私はそれはdoesnの場合、それが存在する場合、DynamoDBの中StringSetに文字列を追加、または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はアレイタイプフィールドへの単純な書き込み/更新ができませんか?空の配列でそのフィールドをインスタンス化することができないので、フィールドを追加または設定しようとする前に、フィールドを最初に参照する必要がありますか?

答えて

1

ADDアクションは、作成/更新ロジックを処理しますが、数値とセットのみをサポートします。文字列タイプ 'S'を追加しようとしています。この文字列を配列にラップし、文字列セット 'SS'として渡す必要があります。あなたはイコールサインも必要ありません。
あなたUpdateExpressionとExpressionAttributeValuesは次のようになります。アイテムの更新について

UpdateExpression: 'ADD socialAccounts :socialAccountId', 
ExpressionAttributeValues: { 
    ':socialAccountId': { 
     'SS': [socialAccountId] 
    } 
}, 

詳しい情報はhere

+0

パーフェクト見つけることができ、これは私の問題を解決しました! –

関連する問題