Dynamodb根据无SQL设计查询所有记录 [英] Dynamodb query all records as per no-sql design

查看:206
本文介绍了Dynamodb根据无SQL设计查询所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道用dynamodb编写查询,但是我还是新手。现在,对于一个
的项目,而不是简单地创建带有分区键和排序键的表,我为
设计了一个用于表的无SQL数据模型数据结构。因此,我已经实现了
list / add / update / delete dynamodb查询。

I know writing queries in dynamodb but I am still new. Now for a project rather than simply creating a table with a partition key and sort key, I have designed a no-sql data-model data structure for my table. Accordingly, I have implemented list/add/update/delete dynamodb queries.

我的问题是如何查询所有记录,例如查询所有产品对于我的应用程序的管理面板,我需要显示实体类型的所有记录,每种类型的实体

My Question is how to query all records, for example query all products. For the Admin panel of my application, I need to display all the records of an entity type, for each type of Entity.

我知道查询所有记录基本上是在>全部检索之前进行的。

I know querying all records has been basically asked before at Retrieve all items from DynamoDB using query?.

但是,我发布了这个没有扫描操作的问题。如何根据或考虑适当/完整的nosql设计进行操作。 我之所以问是因为我当前正在使用静态值作为分区键

However, I am posting this question of doing this without scan operation; how to do in terms of or in the light of considering a proper/complete nosql design. Specifically, I am asking because I am currently using a static value for partition key.

我一直遵循单表设计(无论如何,建议最精心设计的应用程序仅使用1个表)。作为此操作的一部分,请在此链接 https://www.trek10 .com / blog / dynamodb-single-table-relational-modeling / 建议为排序键使用静态值,该键将成为(反向查找)索引的主键。例如,从而允许查询所有产品。

I have followed single table design( in any case, the recommendation is most well-designed applications use only 1 table ). As part of this, at this link https://www.trek10.com/blog/dynamodb-single-table-relational-modeling/ it is recommended to use a static value for sort key, which will become primary key of (reverse lookup) Index. Thereby allowing querying all "Products", for example.

我的应用程序将具有类别。它还将创建调查,每个调查都属于一个类别。对于管理面板,我需要显示所有类别以及所有调查。

My application, will have "Categories". It will also have "Surveys" created, with each Survey belonging to a Category. For the admin panel, I need to display all Categories and also all Surveys.

我目前所做的事情:

I)表设计

表:tbl_surveys

分区键:tbl_pk_surv

排序键:tbl_sk_surv

一个数据属性:data_attr

What I have done currently:
I) Table Design:
table : tbl_surveys
Partition Key: tbl_pk_surv
Sort Key:tbl_sk_surv
One "Data" Attribute: data_attr

我创建了一个一个GSI,其中tbl_sk_surv作为分区键,而 data_attr作为Sortkey >。

I created a GSI with tbl_sk_surv as Partition Key and data_attr as Sortkey.

II)例如,对于类别,类别记录应如下所示:


tbl_pk_surv | tbl_sk_surv | data_attr | cat_name |状态
Cat-1VqNAF3Vi1 | ADMIN_CATEGORY | 1565673999 | Cat1 | 1
Cat-QUTQHQwd42 | ADMIN_CATEGORY | 1565950613 | Cat2 | 1

II) For example, for Categories, Category records would look like this:
tbl_pk_surv | tbl_sk_surv | data_attr | cat_name | status Cat-1VqNAF3Vi1 | ADMIN_CATEGORY | 1565673999 | Cat1 | 1 Cat-QUTQHQwd42 | ADMIN_CATEGORY | 1565950613 | Cat2 | 1

我在查询GSI时使用'ADMIN_CATEGORY'作为GSI哈希键(tbl_sk_surv)的值。

I am querying GSI with 'ADMIN_CATEGORY' as the value for GSI Hash key(tbl_sk_surv).

请让我知道还可以怎么做。通常,请提供有关nosql数据建模的指南。

Please let me know how else this could be done. In general, please provide guidance on nosql data-modelling.

我遵循以下有关nosql设计的文档

> https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ bp-general-nosql-design.html

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql.html

> https://docs.aws.amazon.com/amazondynamodb/latest/ developerguide / bp-modeling-nosql-B.html

https://docs.aws.am azon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html#bp-adjacency-lists

> https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-relational-modeling.html

https:// docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-gsi-overloading.html

> https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-design.html

https: //docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-sort-keys.h tml

https:/ /www.trek10.com/blog/dynamodb-single-table-relational-modeling/

> https://aws.amazon.com/blogs/database/using-sort-keys-to-organize-data -in-amazon-dynamodb /

I have followed following documentation for nosql design
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-general-nosql-design.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html#bp-adjacency-lists
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-relational-modeling.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-gsi-overloading.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-design.html
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-sort-keys.html
https://www.trek10.com/blog/dynamodb-single-table-relational-modeling/
https://aws.amazon.com/blogs/database/using-sort-keys-to-organize-data-in-amazon-dynamodb/

更新
在更多搜索中,我发现下面的问题类似于我的。但是,我要更具体地询问,因为我正在使用GSI。无论哪种方式,请进行指导:

如何设计关键架构以使每个应用程序只有一个DynamoDB表?

推荐答案

我想今天,从您提出问题的5个月起,您已经是dynamodb建模专家了:)我将只为那些希望寻找相同问题并作为自我锻炼的未来访客提供我的观点。

I guess by today, 5 month from your question you already are an dynamodb modeling expert :) I will give my point just for future visitors looking for the same question and as an exercise for my self.

1-第一步(当然,在获得所有用例之后)将设计您的ERM,这将非常有帮助。
2-列出所有访问模式,在对数据库建模之前首先要知道要从数据中获取什么非常重要。
3-然后,您可以确定商品和GSI(如果需要)的PK和SK(如果需要)

1- First Step (after get all your use cases of course) is design your ERM, it will be really helpful. 2- List all your access patterns, is very important to know first what do you want to get from your data before you model your database. 3- Then you can decide your PK and SK(if necessary) for your items and your GSIs(also if needed)

您可以说SK是您GSI PK并像这样查询GSI:

You can say SK is you GSI PK and query the GSI like this:

来自GSI的 PK = ADMIN_CATEGORY

"PK = ADMIN_CATEGORY" from GSI

这篇关于Dynamodb根据无SQL设计查询所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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