我已经将代码示例放在了最基本的基础上,但我仍然无法通过密钥检索单个记录。这是我使用 nodejs 的基本示例(此代码段中未包含凭据):
var dynamodbClient = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: 'newsarticles',
Key: { id: '068d1110-cd0c-11e8-a4d4-57cb772554a4' }
};
//log full dynamodb request object
console.log("request params: ", JSON.stringify(params));
//make dynamodb request
dynamodbClient.get(params, function(err, data) {
if (err) {
console.log("error: " + err)
} else {
console.log(data.Item);
}
});
在上面的示例中运行此代码会给我以下错误:
ValidationException:提供的关键元素与架构不匹配
我的数据集很容易插入,系统中的记录如下例所示:
{
"added": 1539231216801,
"description": "A number of ethics complaints filed against Supreme Court Justice Brett Kavanaugh have yet to be resolved and will be transferred to a new jurisdiction, Chief Justice John Roberts wrote in a letter Wednesday. ",
"edited": 1539231216402,
"id": "068d1110-cd0c-11e8-a4d4-57cb772554a4",
"largeImageUrl": "https://fm.cnbc.com/applications/cnbc.com/resources/img/editorial/2018/10/09/105496148-1539094642099gettyimages-1047769784.1910x1000.jpeg",
"newstitle": "Ethics complaints against Brett Kavanaugh have not been resolved yet",
"newsurl": "https://www.cnbc.com/2018/10/10/ethics-complaints-against-brett-kavanaugh-have-not-been-resolved-yet.html",
"posted": 1539231216402,
"scrapeid": "05c3a690-cd0c-11e8-a4d4-57cb772554a4",
"scrapes": [
"05c3a690-cd0c-11e8-a4d4-57cb772554a4"
],
"source": "www.cnbc.com",
"type": "rate"
}
该表定义如下:
表名:newsarticles
主分区键: id(字符串)
主排序键: 添加(数字)
错误消息并没有真正告诉我问题所在。谁能看到我的请求有什么问题?是否有另一种方法来诊断可能丢失或不正确的内容?在此先感谢,对于 NOOB 问题,我很抱歉,但我只是第一次开始使用 AWS DynamoDB。