[英]Making delete, update, insert and get operations nested json data structure on dynamodb
My data structure is like below:我的数据结构如下:
I want update,delete a room in the rooms list with roomId.我想更新,删除房间列表中带有 roomId 的房间。 Should i add a secondary index to roomId?
我应该向 roomId 添加二级索引吗? How should be update and delete queries?
应该如何更新和删除查询? Also i want to get room informations with roomId.
我也想用 roomId 获取房间信息。
For remove a room, can the code structure be like that:对于移除房间,代码结构可以是这样的:
const roomItem = {
TableName: 'Home',
Key: {
homeId: homeId
},
IndexName: 'roomId-index',
ConditionExpression: 'rooms.roomId = :roomId',
ExpressionAttributeValues: {
':roomId': roomId
}
};
await dynamodb.delete(roomItem).promise();
Creating a Secondary Index on a non top-level Attribute在非顶级属性上创建二级索引
You cannot create a Secondary Index
on rooms.roomId
where it is a nested attribute您不能在作为嵌套属性的
rooms.roomId
上创建Secondary Index
See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html请参阅https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html
Every attribute in the index key schema must be a top-level attribute of type String, Number, or Binary.
索引键架构中的每个属性都必须是字符串、数字或二进制类型的顶级属性。
-- --
To be able to retrieve by roomId
, you have the options of either:为了能够通过
roomId
进行检索,您可以选择:
Scan
, orScan
,或roomId
a / part of a Table's Key
in a new Table
so that you can use achieve milliseconds Query
retrievalroomId
成为新Table
中表的Key
的 / 一部分,以便您可以使用实现毫秒Query
检索Example例子
Hash Key (House Id) | Range Key (Room Id)
---------------------+---------------------
55555555 | 1
---------------------+---------------------
55555555 | 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.