如何在 DynamoDB 中使用 IN 条件查询 table

How to query a table by using IN conditions in DynamoDB

努力寻找一个示例,说明如何从给定列表中查询 table 到 return 行的 ID。

下面的查询抛出包含 IN

var params = {
            id: '7deb3df9-552b-47a4-aef3-ad601f141d50'
        };

        var p = {
            TableName: 'players',
            KeyConditionExpression: 'id IN (:id)',
            ExpressionAttributeValues: buildQuery(params)
        };

您不能将 "IN" 运算符与 KeyConditionExpression 一起使用,请参阅

中的详细信息

您可能想使用 batchGetItem 而不是查询,但效率不高。

您的参数可能如下所示:

var params = {
    RequestItems: {
      'players': {
        Keys: [{
          id: "7deb3df9-552b-47a4-aef3-ad601f141d50",
          rangeKey: "<range key 1>" // <--- if your table has a range key, you must specify its value here
        }, {
          id: "<ANOTHER ID 2>",
          rangeKey: "<range key 2>"
        }, {
          id: "<ANOTHER ID 3>",
          rangeKey: "<range key 3>"
        }]
      }
    } 
};
dynamodbDoc.batchGet(params, function(err, data) {

});