DynamoDB 查询中未定义的地图列表 returns
List of Maps returns undefined in DynamoDB query
我正在查询 DynamoDB。它有一个名为 'Multiple Units' 的属性,结构如下:List [ Map { Map { S }, S }, ... ]
我在本地测试了一个 lambda:
module.exports.getByAddress = async (event) => {
const params = {
TableName: process.env.tableName,
Key: {
Address: event.pathParameters.address
}
};
var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
docClient.get(params).promise().then(
returnResult => console.log(returnResult)
)
}
这是输出:
Item: {
...
license: '',
Coordinates: { lng: '-71.075985', lat: '42.346096' },
'Multiple Units': [ [Object], [Object], [Object], [Object], [Object], [Object] ],
...
}
当我尝试 console.log 具体列出多个单位时,我得到了未定义的信息。
在阅读 DynamoDB get/getItem 时,我猜它与异步有关,但我无法配置将导致正确输出的更改。
根据您的评论,您提到在执行 console.log(returnResult['Multiple Units'])
时得到 undefined
。
仔细看看 console.log(returnResult)
正在打印什么:
Item: {
...
license: '',
Coordinates: { lng: '-71.075985', lat: '42.346096' },
'Multiple Units': [ [Object], [Object], [Object], [Object], [Object], [Object] ],
...
}
请注意,它正在使用 Item
键打印 map
。因此,要获取您的数据,请尝试 console.log(returnResult.Item['Multiple Units'])
您可以查看 DynamoDB SDK API 以了解有关 get
调用结果的更多信息。
我正在查询 DynamoDB。它有一个名为 'Multiple Units' 的属性,结构如下:List [ Map { Map { S }, S }, ... ]
我在本地测试了一个 lambda:
module.exports.getByAddress = async (event) => {
const params = {
TableName: process.env.tableName,
Key: {
Address: event.pathParameters.address
}
};
var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
docClient.get(params).promise().then(
returnResult => console.log(returnResult)
)
}
这是输出:
Item: {
...
license: '',
Coordinates: { lng: '-71.075985', lat: '42.346096' },
'Multiple Units': [ [Object], [Object], [Object], [Object], [Object], [Object] ],
...
}
当我尝试 console.log 具体列出多个单位时,我得到了未定义的信息。 在阅读 DynamoDB get/getItem 时,我猜它与异步有关,但我无法配置将导致正确输出的更改。
根据您的评论,您提到在执行 console.log(returnResult['Multiple Units'])
时得到 undefined
。
仔细看看 console.log(returnResult)
正在打印什么:
Item: {
...
license: '',
Coordinates: { lng: '-71.075985', lat: '42.346096' },
'Multiple Units': [ [Object], [Object], [Object], [Object], [Object], [Object] ],
...
}
请注意,它正在使用 Item
键打印 map
。因此,要获取您的数据,请尝试 console.log(returnResult.Item['Multiple Units'])
您可以查看 DynamoDB SDK API 以了解有关 get
调用结果的更多信息。