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

查看:69
本文介绍了如何在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.

要求:应该能够检索到客户和杂物物品的单独列表。

租金详细信息-哪个客户借用了哪个Hardeware物品。

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

我提到了-二级索引表。这是关于将所有列保留在一个表中。

我认为有2个DynamoDb表:

客户-这具有类似于列的所有属性以及一组硬件Item哈希键。 (然后,我的问题是,当查询客户表以仅检索客户时,还将加载所有硬件密钥。)

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.

您的客户表中可能会有一个称为硬件的属性。该属性将是客户拥有的硬件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,请在硬件表上执行GetItem。

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

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天全站免登陆