Reputation: 398
I have a problem with modelling my m:n relation in dynamodb. I have studied the docs and found an example using the adjacency list pattern which is very simliar to my case:
Now to the problem: My single most common query of my app would be "Give me all invoices related to a specific bill id"
How can I do that without first having to querying for all invoiceIds (via a reversed index) and then fetch all the invoices individually by their ids?
Upvotes: 2
Views: 210
Reputation: 14859
If you've not already come across it, https://stackoverflow.com/a/50238513/4985580 gives a bit more detail about how this pattern is implemented, and will make the answer below more comprehensible.
Basically you simply do a GSI Query using your BillId as the partition key. Then for each item you find the range key provides you with the associated InvoiceId.
Its just one Query and you get all of the InvoiceIds linked to the Bill.
Upvotes: 3