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



在lambda中,我在一个表上调用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...
}
});

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

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

我在文档或任何谷歌搜索中都找不到答案。

如果Projection-Expression包含表中不存在的属性,则不会抛出任何错误或返回null。

它将不会出现在结果中,并返回找到的其余属性。

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

相关内容

最新更新