问题
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