gpt4 book ai didi

node.js - 如何将 'BatchGetItem' 用于 NodeJS AWS-SDK for DynamoDB

转载 作者:IT老高 更新时间:2023-10-28 23:19:29 27 4
gpt4 key购买 nike

我正在尝试使用 Node JS AWS-SDK 从 DynamoDB 表中获取项目。 getItem 函数工作正常,但 BatchGetItem 更难使用。

我使用官方文档: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/Client.html#batchGetItem-property

我正在寻找有关如何正确使用此功能的示例,但我找不到任何示例。我写的代码是:

var params = {

"RequestItems" : {
"Keys" : [
{"HashKeyElement" : { "N" : "1000" } },
{"HashKeyElement" : { "N" : "1001" } }
]
}
}

db.client.batchGetItem(params, function(err, data) {
console.log('error: '+ err);
console.log(jsDump.parse(data));
});

我收到 SerializationException: Start of list found where not expected 错误,但就我的 NodeJS 和 JSON 专业知识而言,我的语法是正确的。但这令人困惑: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_BatchGetItems.html

在该语法示例中,您必须提供表名。

最佳答案

我使用的是 dynamo db 客户端版本……经过一个小时的研究,我设法让它工作了……

var params = {

RequestItems: { // map of TableName to list of Key to get from each table
Music: {
Keys: [ // a list of primary key value maps
{
Artist: 'No One You Know',
SongTitle:'Call Me Today'
// ... more key attributes, if the primary key is hash/range
},
// ... more keys to get from this table ...
],
AttributesToGet: [ // option (attributes to retrieve from this table)
'AlbumTitle',
// ... more attribute names ...
],
ConsistentRead: false, // optional (true | false)
},
// ... more tables and keys ...
},
ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES)
};
docClient.batchGet(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response

});

关于node.js - 如何将 'BatchGetItem' 用于 NodeJS AWS-SDK for DynamoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15043043/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com