Vic*_*r S 11 javascript amazon-web-services node.js amazon-dynamodb
我有以下列表示例:
{
"favorites": [
{
"createdAt": 1448998673852,
"entityId": "558da3de395b1aee2d6b7d2b",
"type": "media"
},
{
"createdAt": 1448998789252,
"entityId": "558da3de395b1aee2d6b7d83",
"type": "media"
},
{
"createdAt": 1448998793729,
"entityId": "558da3de395b1aee2d6b7d99",
"type": "media"
},
{
"createdAt": 1448998813023,
"entityId": "558da3de395b1aee2d6b7daf",
"type": "media"
}
],
"userId": "2"
}
Run Code Online (Sandbox Code Playgroud)
我想删除地图:"entityId": "558da3de395b1aee2d6b7d2b".
我正在考虑一个UpdateItem查询,我查看了REMOVE表达文档(http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html),但我似乎无法看到任何示例,除了通过索引值从List中删除项目....
我已经多次遇到这个问题,不幸的是没有直接的解决方案。我遇到的两种最常见的解决方法是:
A. 使用地图而不是列表,您现在可以使用 直接在更新表达式中引用收藏夹#favorites.#entityId。如果顺序很重要,请为每个地图添加顺序属性。在数据访问层中,您需要与所需的数组类型进行转换。
{
"userId": "2",
"favorites": {
"558da3de395b1aee2d6b7d2b": {
"createdAt": 1448998673852,
"entityId": "558da3de395b1aee2d6b7d2b",
"type": "media",
},
// ... more entities here
}
}
Run Code Online (Sandbox Code Playgroud)
B. 使用一对多表,请参阅http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForItems.html
| 归档时间: |
|
| 查看次数: |
1528 次 |
| 最近记录: |