我有以下列表示例:
{
"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"
}
我想使用删除地图"entityId": "558da3de395b1aee2d6b7d2b"
。
我在考虑一个UpdateItem查询,我查看了REMOVE表达式文档(http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html),但似乎看不到任何示例,而不是按索引值从列表中删除项目...。
我已经几次遇到这个问题了,不幸的是,没有简单的解决方案。我遇到的两个最常见的解决方法是:
A.使用地图代替列表,您现在可以使用在更新表达式中直接引用收藏夹#favorites.#entityId
。如果订单很重要,请向每个地图添加订单属性。在数据访问层中,您需要在所需的数组类型之间进行转换。
{
"userId": "2",
"favorites": {
"558da3de395b1aee2d6b7d2b": {
"createdAt": 1448998673852,
"entityId": "558da3de395b1aee2d6b7d2b",
"type": "media",
},
// ... more entities here
}
}
B.改用一对多表格,请参阅http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForItems.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句