简体   繁体   English

AWS DynamoDB中的值可以指向其他表中的值吗?

[英]Can a value in AWS DynamoDB point to value in different table?

First off, I have very minimal experience with servers and databases (I have only used it once in my entire life and only beginning to learn) and this would not exactly be a "code" question strictly speaking because it is a question concerning a concept regarding DynamoDB.. But here it is because I cannot find answer to it no matter how much I search! 首先,我对服务器和数据库的经验非常少(我一生只使用过一次,并且才开始学习),严格来讲,这并不是一个“代码”问题,因为这是一个与概念有关的问题关于DynamoDB的问题。但这是因为无论搜索多少,我都找不到答案!

I am trying to make an application where users can see if their friends are "online" or not. 我正在尝试创建一个应用程序,使用户可以查看其朋友是否“在线”。 There will be a table that keeps track of the users who are online and offline like this: 将有一个表来跟踪这样的在线和离线用户:

user_id | online
1       | O
2       | X
3       | O

and when user_id 1 who has friends 2 & 3 "refreshes", 1 would be able to see that 2 is offline and 3 is online. 而当拥有朋友2和3的user_id 1“刷新”时,1可以看到2处于离线状态,而3处于在线状态。 This would normally be done by batch_get in dynamodb, but each item I read would count as one unit, meaning if user1 had 20 friends, one refresh would use up 20 read units. 这通常由dynamodb中的batch_get完成,但是我读取的每个项目都将计为一个单位,这意味着如果user1有20个朋友,则一次刷新将消耗20个读取单位。 To me, that would cost too much, and I thought that if I made a table for each user that would hold list of their friends that shows whether they are online or not, each refresh would cost only one read unit. 对我而言,这会花费太多,而且我认为,如果为每个用户创建一张表,其中包含他们的朋友列表,以显示他们是否在线,则每次刷新将仅花费一个读取单元。

user_id | friends_on_off_line
1       | {2:X, 3:O}
2       | {1:O}
3       | {1:O}

However, the values in the list would have to be a "pointer" to the first table, because I cannot update the value everytime someone goes online or offline (if 1 went offline, I would have to write 1 as offline to both tables, and in second table, write it twice, using 3 write units which would end up costing even more) So I am trying to make it so that in second table, values would point to the first table that would read whether they are online/offline and return the values as a list using only 1 read unit: like this 但是,列表中的值必须是第一个表的“指针”,因为每次有人上线或下线时我都无法更新该值(如果1脱机,则我必须在两个表中都写1脱机,然后在第二张表中写入两次,使用3个写入单元,这最终将花费更多。)因此,我试图使它在第二张表中指向第一个表,该表将读取它们是否在线/离线并仅使用1个读取单位将这些值作为列表返回:

user_id | friends_on_off_line
1       | {pointer_to_2.online , pointer_to_3.online}
2       | {pointer_to_1.online}
3       | {pointer_to_1.online}

Is this possible in DynamoDB? 在DynamoDB中这可能吗? If not, which service should I use and how can I make it possible? 如果没有,应该使用哪种服务?如何使之成为可能? Thanks in advance! 提前致谢!

I don't think DynamoDB is the right tool for this kind of job. 我认为DynamoDB不是适合这种工作的工具。

SQL databases (Mysql/PostgreSQL) both have easy designs - just use joins (pointers). SQL数据库(Mysql / PostgreSQL)都有简单的设计-只需使用联接(指针)即可。

You can also look at this question regarding this area for MongoDB. 您还可以查看有关MongoDB的有关此区域的问题

What you should ask yourself is what are the most common questions the database needs to answer and what is the update / read rate. 您应该问自己的问题是数据库需要回答的最常见问题是什么,更新/读取速率是多少。 This questions usually navigate you to the right direction when picking up a database. 在选择数据库时,这些问题通常会将您导航到正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM