如何在 DynamoDB 中处理多对多 [英] How to handle many to many in DynamoDB

查看:17
本文介绍了如何在 DynamoDB 中处理多对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 NoSql 和 DynamoDb 的新手,但来自 RDBMS..我的表正在从 MySql 移动到 DynamoDb.我有桌子:
客户(列:cid [PK]、姓名、联系人)
硬件(列:hid[PK]、名称、类型)
租金(列:rid[PK]、cid、hid、time).=> 这是客户和硬件项目的关联.

I am new to NoSql and DynamoDb, but from RDBMS.. My tables are being moved from MySql to DynamoDb. I have tables:
customer (columns: cid [PK], name, contact)
Hardware (columns: hid[PK], name, type )
Rent (columns: rid[PK], cid, hid, time) . => this is the association of customer and Hardware item.

一个客户可以拥有多个硬件项目,并且一个硬件项目可以在多个客户之间共享.

one customer can have many Hardware Items and one Hardware Item can be shared among many customers.

要求:客户和硬件项目的单独列表应该能够检索.
租金详细信息 - 哪个客户租用了哪个硬件项目.

Requirements: seperate lists of customers and hadware items should be able to retrieve.
Rent details- which customer barrowed which Hardeware Item.

我参考了 this - 二级索引表.这是关于将所有列保留在一个表中.
我想有 2 个 DynamoDb 表:
客户 - 这具有类似于列和一组硬件项目哈希键的所有属性.(然后我的问题是,当查询客户表以仅检索客户时,所有硬件密钥也被加载.)

I referred this - secondary index table. This is about keeping all columns in one table.
I thought to have 2 DynamoDb tables:
Customer - This has all attributes similar to columns AND set of hardware Item hash keys. (Then my issue is, when customer table is queried to retrieve only customers, all hardware keys are also loaded.)

请对表结构有任何指导吗?如何保存、加载甚至更新?
请问有java示例吗?(找不到任何与我的场景类似的有用资源)

Any guidance please for table structure? How to save, and load, and even updates ?
Any java samples please? (couldn't find any useful resource which similar to my scenario)

推荐答案

看看这个答案,因为它涵盖许多与您相关的基础知识.

Take a look at this answer, as it covers many of the basics which are relevant to you.

DynamoDB 本身不支持外键.每个表都是独立的,没有特殊的工具可以使两个表保持同步.

DynamoDB does not support foreign keys as such. Each table is independent and there are no special tools for keeping two tables synchronised.

您的客户表中可能有一个名为hardwares 的属性.该属性将是客户拥有的硬件 ID 列表.如果您想查看属于某个客户的所有硬件项目,您可以:

You would probably have an attribute in your customers table called hardwares. The attribute would be a list of hardware ids the customer has. If you wanted to see all hardware items belonging to a customer you would:

  1. 对客户 ID 执行 GetItem.或者根据您查找客户的方式使用查询.
  2. 对于客户硬件属性中的每个硬件 ID,对 Hardware 表执行 GetItem.

相对于 RDBMS 解决方案,使用 DynamoDB,您通常最终会在客户端应用程序中做更多事情.好处是它快速而简单.但是您会发现您可能会将大量工作从数据库服务器转移到客户端服务器.

With DynamoDB you generally end up doing more in the client application relative to an RDBMS solution. The benefits are that its fast and simple. But you will find you probably move a lot of your work from the database server to your client server.

这篇关于如何在 DynamoDB 中处理多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆