How to query all items of a specific type?

0

I have a dynamo table, and have two main types of items: groups and users. I am using groupIds and userIds as partition keys, and userIds and groupIds as sort keys. In this way I am able to map many to many relationships. So querying a userId I can get all of the users groups, and querying a group I can get all of the users in that group.

I'm wondering if there is a way to architect it in such a way where I can easily query all groups without performing a scan?

My thought is to have a partition key that is just something like "groups" and a sort key of groupIds. Is this a proper approach?

質問済み 2年前855ビュー
1回答
1

What do you mean by "query all groups"? Get a list of group names? I'm going to assume so with my answer here.

Within each item collection for a group do you have an item which holds the metadata about that group? So the other items in the item collection are the users, but the one item is about the group itself? Having the group name and such. I'm guessing yes.

Setup a GSI having a PK of whatever attribute stores the group name. Then with a scan of the GSI you can get all the group metadata items and nothing else (because nothing else is in the GSI), so it's efficient. Project into the GSI whatever attributes are needed for that "query all groups" query.

Again, I'm making a lot of assumptions here on what you really intend.

AWS
回答済み 2年前
  • Yes, you are right in assuming I meant "Get a list of group names". And yes there is an item for each group that holds the metadata about that specific group. The other items in the collection are the users.

    I think you have a good approach, and I will try this out.

    Thank you for your help, and you did a good job at making assumptions :)

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ