简体   繁体   English

在dynamodb中获取关系数据

[英]Get relational data in dynamodb

I have studied many articles and blogs and finally conclude that I need only one base table for whole application and then many Global Secondary Indexes according to my access patterns. 我研究了许多文章和博客,最后得出结论:对于整个应用程序,我只需要一个基表,然后根据我的访问模式就可以使用许多全局二级索引。 Now I have stuck in a problem. 现在我陷入了一个问题。

My base table structure is:- 我的基本表结构是:

**PK** **SK** **data** **PK** **SK** **data**

university uni_uuid name university uni_uuid name

course course_uuid uni_uuid course course_uuid uni_uuid

As you see when I will add a new course it will always have a university uuid which will save under university_uuid key with course record. 如您所见,当我添加新课程时,它将始终具有大学uuid,该大学uuid将保存在university_uuid键下并带有课程记录。

Now I want to list all the courses to Admin. 现在,我想列出所有要管理的课程。 So I query the dynamodb like:- 所以我查询dynamodb像:

var params = {
      TableName: "BaseTable",
      FilterExpression:"PK = :type",
      ExpressionAttributeValues: {
          ":type": "Course"
      }
  };

  docClient.scan(params, onScan);
  var count = 0;

  function onScan(err, result) {
      if (err) {
          console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
      } else {        
          resolve(result);
      }
  }

This successfully returns me all the added courses. 这将成功返回所有添加的课程。 Like:- 喜欢:- 在此处输入图片说明

Now my question is that how can I show University name in the column University. 现在我的问题是,如何在“大学”列中显示大学名称。 Currently university_uuid is displaying here. 目前在这里显示university_uuid。 Do I need to run another query and find university name by its uuid, if so then for 100 courses I need to run 100 more queries for each course university name. 我是否需要运行另一个查询并通过其uuid查找大学名称,如果是这样,那么对于100门课程,我需要为每个课程的大学名称运行100个查询。

Any help will deeply appreciated!! 任何帮助将深表感谢!

Approaches: 处理办法:

  1. If university name will not be changed in Admin you can use denormalization and include it into courses table. 如果在Admin中不会更改大学名称,则可以使用非规范化并将其包含在课程表中。 Even if university name can be changed, on update you can get all corresponded courses by uni_uuid and update redundant data. 即使可以更改大学名称,在更新时,您也可以通过uni_uuid获取所有对应的课程并更新冗余数据。
  2. When you receive courses list, distinct uni_uuid and then request data from universities using IN clouse. 当您收到课程列表时,请使用独特的uni_uuid,然后使用IN Clouse向大学索取数据。

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

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