单个API请求中的多个DynamoDB查询不好练习
我正在尝试创建我的第一个基于DynamoDB的项目,并且在找出使用NOSQL数据库的最佳实践时遇到了一些麻烦。
我的用户酶目前正在存储用户和团队。我有一个表格,该表具有用户#{userId}
> team {#teamid} 的分区键。如果PK是Team {#teamId}
我使用SK存储记录actem#{teamID}
用于团队详细信息,或user#{userId}
>有关用户在团队中的详细信息(AccessedInvite
,加入
等)。我也有一个基于userId/email
列的GSI,它允许我查询用户已发射到的所有团队或用户团队,具体取决于AccessedInvite的值字段。目前,表结构的附加屏幕截图:
在我的应用程序中,我有一个访问模式,可以使团队的团队成员获得一个用户ID。
目前,我正在在我的lambda函数中进行两个查询:
- 获取用户团队,通过查询
pk = {userId}的GSI和Fitler AccessedInvite = true
- 通过在
pk = {teamID}和SK BEGINS_WITH用户#
这很好,但是我担心我需要在我的API函数中预先两个单独的DynamoDB调用。
我想知道是否有更好的方法来表示此访问模式,并且是否真的很糟糕,因为我看不到另一种方法来执行此操作。
任何形式的反馈都将不胜感激!
I'm trying to create my first DynamoDB based project and I'm having some trouble figuring out the best practices working with a NoSQL database.
My usecase currently is storing users and teams. I have a table that has a partition key of either USER#{userId}
or TEAM{#teamId}
. If the PK is TEAM{#teamId}
I store records with SK either TEAM#{teamId}
for team details, or USER#{userId}
for the user's details in the team (acceptedInvite
, joinDate
etc). I also have a GSI based on the userId/email
column that allows me to query all the teams a user has been invted to, or the user's team, depending on the value of acceptedInvite
field. Attached screenshots of the table structure at the moment:
In my application I have an access pattern of getting a team's team members, given a user id.
Currently, I'm doing two queries in my lambda function:
- Get user's team, by querying the GSI on
PK = {userId} and fitler acceptedInvite = true
- Get the team data by querying the table on
PK = {teamId} and SK begins_with USER#
This works fine, but I'm concerned I need to preform two separate DynamoDB calls in my API function.
I'm wondering if there's a better way to represent this access pattern and if multiple dynamoDB calls are actually that bad, since I cannot see another way to do this.
Any kind of feedback is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
避免进行两个查询的最佳方法是向API呼叫者提供提出单个DynamoDB请求所需的所有信息。对于您的情况,这意味着向呼叫者提供TeamID。您可以作为列表操作响应的一部分,或者如果是经过身份验证的用户,则可以作为其在JWT中的索赔的一部分来执行此操作。
The best way to avoid making two queries like this is to supply the API caller with all the information needed to make a single DynamoDB request. For your case this means supplying the caller with the teamId. You can do this as either as part of a list operation response, or if it is the authenticated user, then as part of their claims in a JWT.