-----------------下面提供了更多混凝土示例-----------------
我具有以下功能,可以从参数中获取用户,姓名,性别,并为该用户更新现有客户端。
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": []}},
}
我在做什么错了?