如果您使用投影表达式在 DynamoDb 中执行获取项目,如果表达式中的属性可能不存在,会发生什么情况

What happens if you do a get item in DynamoDb using a projection expression, if the attribute in the expression may not exist

在 lambda 中,我在 table 上调用 getItem,并使用单个字段的投影表达式。这工作正常。

const usersTableParams = {
  TableName: 'users',
  Key: {
    'user-name': { S: userID }
  },
  ProjectionExpression: 'notificationEndpointARN'
};

ddb.getItem(usersTableParams, function (err, data) {
  if (err) {
    console.log('error getting user info', err);
  }
  else {
    // success
    // code...
  }
});

现在我想向投影表达式添加另一个属性,但该属性可能还不存在于项目中。 (如果它不存在我会在函数的末尾添加它)。

该函数是否失败,是否 return 该属性为 null,它根本不 return 该属性?

我无法在 documentation 或任何 google 搜索中找到答案。

如果 Projection-Expression 包含 table 中不存在的属性,它不会抛出任何错误或 return null。

它不会出现在结果中,return 剩下的找到的属性。

cli> aws dynamodb get-item --table-name my-DynamoDBTable-I3BL7EX05JQR --key file://test.json --projection-expression "data_type,ts,username"  
{
    "Item": {
        "ts": {
            "N": "1600755209826"
        },
        "data_type": {
            "S": "Int32"
        }
    }
}

详情可以参考:https://docs.aws.amazon.com/cli/latest/reference/dynamodb/get-item.html