【发布时间】:2022-01-22 06:16:59
【问题描述】:
我在 dynamo 中有一张地图,其结构如下:
participants: {
M: {
"6ecd8c99-4036-403d-bf84-cf8400f67836": {
M: {
participantUid: {
S: "6ecd8c99-4036-403d-bf84-cf8400f67836",
},
userSummary: {
M: {
userRef: {
S: "refGoesHere",
},
},
},
isRead: {
BOOL: false,
},
},
},
},
},
我正在尝试使用以下命令更新 isRead 属性:
const updateReadStatusCommand = new UpdateCommand({
TableName: config.database,
Key: {
PK: `TASK#${taskUid}#CLIENT#${client}`,
SK: `THREAD#${uid}`,
},
UpdateExpression: `SET participants.#participantUid.isRead = :isRead`,
ExpressionAttributeNames: {
"#participantUid": userUid,
},
ExpressionAttributeValues: {
":isRead": updateBody.isRead,
},
ReturnValues: "ALL_NEW",
});
到目前为止,我一直遇到以下错误:The document path provided in the update expression is invalid for update。
我很难在这里看到问题,因为它无法识别地图中的属性。谁能指出我正确的方向?
编辑:
我还扫描了表格以确保数据格式正确,看起来像这样:
"participants": {
"6ecd8c99-4036-403d-bf84-cf8400f67836": {
"isRead": false,
"participantUid": "6ecd8c99-4036-403d-bf84-cf8400f67836",
"userSummary": {
"userRef": "refGoesHere"
}
}
},
【问题讨论】:
-
如果您确实找到了正确答案,请发布,我很感兴趣
-
如果您不小心将地图保存为 DynamDB JSON 格式,则会解释错误路径错误。单击控制台中的表项(转到
Item Editor)。View DynamoDB JSON关闭时你看到的属性格式是什么? -
我刚刚将扫描的内容粘贴到数据库中 :)
-
作为模板字符串的 UpdateExpression 也困扰着我:D 你能尝试使用标准的“”字符串吗?
-
不走运。我还仔细检查了命令中输出的内容:UpdateExpression: 'SET #participants.#participantUid.#isRead = :isRead', ExpressionAttributeNames: { '#participantUid': '6ecd8c99-4036-403d-bf84-cf8400f67836 ', '#isRead': 'isRead', '#participants': 'participants' }, ExpressionAttributeValues: { ':isRead': true },
标签: javascript amazon-web-services amazon-dynamodb