由于AttributeValues,DynamoDB覆盖现有键值对

时间:2019-05-27 01:56:44

标签: amazon-web-services amazon-dynamodb aws-sdk

-----------------下面提供了更多混凝土示例-----------------

我具有以下功能,可以从参数中获取用户,姓名,性别,并为该用户更新现有客户端。

function createRecord(user, personName, sex) {
  var sexPayload = [];
  var dynamoParams = {
    TableName: 'account',
    Key: {
      id: user
    },
    UpdateExpression: "set #client.#person.#sex = :sexPayload",
    ExpressionAttributeNames: {
      "#client": "client",
      "#person": personName,
      "#sex": sex
    },
    ExpressionAttributeValues: {
        ":sexPayload": sexPayload,
    },
    ConditionalExpression: "attribute_not_exists(#client.#person.#sex)"
  };
  docClient.update(dynamoParams, function(err, data){
    something...
  });
}

如果personName =“ John” sex =“ man”, 这将创建

client: {
    John: {"M": {"man": {"L": []}}},
}

当我传递另一个名字=“ John” sex =“ female”时, 这会覆盖现有的约翰“男人”,并在约翰下写“女性”

client: {
    John: {"M": {"female": {"L": []}}},
}

我想要实现的是:

client: {
    John: {"M": {"man": {"L": []}, {"female": {"L": []}},
}

我在做什么错了?

0 个答案:

没有答案