[英]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: 处理办法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.