小编Ste*_*ett的帖子

如果 StringSet 不存在,则附加到或创建它

所以这应该很简单......

如果存在,我想将字符串附加到 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);
});
Run Code Online (Sandbox Code Playgroud)

我也试过...

  UpdateExpression: 'SET socialAccounts = list_append(socialAccounts, :socialAccountId)',
  ExpressionAttributeValues: {
    ':socialAccountId': {
      S: socialAccountId …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-dynamodb aws-lambda

6
推荐指数
1
解决办法
2779
查看次数