仅使用JavaScript从DynamoDB中的一行检索特定数据




使用DynamoDb和此处提供的"读取"功能,我将如何仅检索特定项目(例如,仅检索名字、姓氏和城市(
我可能需要添加某种过滤器,但我找不到任何可以使用的过滤器。

这是我的表结构(bpNumber是主键(:

Item:{
            "salutationCode": "02",
            "lastName1": "Berg",
            "firstName": "Anne",
            "street": "Am Dächle",
            "streetNumber": "22/2",
            "zipcode": "33425",
            "countryCode": "DE",
            "city": "Hausen",
            "bpNumber": 222,
            "dateOfBirth": "1955-07-01",
            "attri": [
              {
                "attri1":"nonono"
              },
              {
                "attri2": "yeayeayea"
              }
            ]
        }

这就是我正在使用的"读取"方法:

read(){
        var docClient = new AWS.DynamoDB.DocumentClient()
        var table = "businessPartnersData";
        var bpNumber = 222;
        var params = {
            TableName: table,
            Key:{
                "bpNumber": bpNumber
            }
        };
        docClient.get(params, function(err, data) {
            if (err) {
                console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
            } else {
                console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
            }
        });
  }

谢谢你抽出时间!

您可以使用ProjectionExpression:

params.ProjectionExpression = "firstname, lastname, city";

这将只在结果集中为所有项返回这些属性。

最新更新