我在DynamoDB表中有一项。该项目如下:
{
data: [ 1, 2, 3, 4, 5, 6 ]
more_data: [ 2, 3, 4, 5, 6, 7 ]
}
使用ProjectionExpression,我可以执行一个GetItem
,并且只返回data
,或者返回data[0]
。但有两件事我搞不懂:
data.SIZE
?data[2-10]
ProjectionExpression文档似乎没有涵盖这一点。有什么线索吗?
发布于 2016-11-30 21:39:37
1) List
属性的大小,DynamoDB没有一个函数。可以使用length
函数在客户端找到数组元素的大小。
data.Item.records.length
给出数组元素records
的长度。records
是DynamoDB表中的列表。
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));
console.log(data.Item[0].records.length);
}
});
2)在子数组中,语法应该是这样的。DynamoDB不像'records[1-3]'
那样支持范围。
ProjectionExpression: 'records[0], records[1]',
3) DynamoDB没有一个函数来获取列表中的最后一项。但是,您可以在客户端获得它。我有records
列表。我使用itemValue.records[itemValue.records.length - 1]
获得最后一个元素
docClient.query(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));
data.Items.forEach(function(itemValue) {
console.log (itemValue.records[itemValue.records.length - 1]);
});
}
});
发布于 2021-06-22 06:50:41
https://stackoverflow.com/questions/40882426
复制相似问题