Querying many-to-many in DynamoDB with Node.js

时光怂恿深爱的人放手 提交于 2019-12-14 02:12:20

问题


I was reading about how to model many-to-many relationships in DynamoDB from this article: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html

Let's say that the requirement is to display a list of all Bills for a given Invoice. But you need to display all attributes for each bill (red circles in the image).

I could query all the Bills for Invoice-92551 as follow:

    var params = {
       TableName: "some-table",
       KeyConditionExpression: "#pk = :pk",
       ExpressionAttributeNames: {
          "#pk":"pk",
       },
       ExpressionAttributeValues: {
          ":pk": "Invoice-92551"
       },
       ProjectionExpression: "pk, sk, isPaid, Amount, created...etc"
    }; 

docClient.query(params, function(error, billsForGivenInvoice) {...});

Ok, I have now the bills but I need more attributes for each of them. I could do the following:

            var params = {
                RequestItems: {
                    "some-table": {
                        Keys: ["Bill-4224663", "Bill-4224687"],
                        ProjectionExpression: "...other attributes needed..."
                    }
                }
            };

            docClient.batchGet(params, function(error, bills) {});

Is it possible to query both results in one go?. Instead of calling first to query() and them a batchGet().

来源:https://stackoverflow.com/questions/50704656/querying-many-to-many-in-dynamodb-with-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!