I have a model where a user can access multiple files and a file can belong to many users, hence the many-to-many structure. I'm interested in using DynamoDb for this, even though there is no native relational support. From other posts, I think I can start with the following structure:
With this structure, I can do things like "list all the files available to a user" via the pseudo-sql code SELECT * FROM table WHERE PK=user AND SK.startsWith("FILE#")
.
However I'm not sure how I could do something like "retrieve the file X for user Y" via this structure. This seems to involve two queries:
SELECT * FROM t WHERE PK=FILE#X and SK=FILE#X
. Otherwise fail.This seems to defeat the purpose of the structure, which is minimising IOPS. How do I go about solving this problem and only requiring one query for this access pattern?
You either do two requests or you denormalize the file data into the item held under the user.
Or you could create a list of shared-with users within the file item, but that's usually not going to scale well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.