gpt4 book ai didi

node.js - 如何重新格式化来自 Node.js 客户端的 DynamoDB 响应

转载 作者:太空宇宙 更新时间:2023-11-03 23:29:38 26 4
gpt4 key购买 nike

当我使用 aws nodejs 客户端从 dynamoDB 发出获取请求时,结果包含以类型作为键的响应,即

{
Item: {
newrelic_id: {
S: 'nr-1234'
}
,
jumpcloud_id: {
S: 'j-234'
}
,
microtime: {
N: '1475690490854'
}
,
instance_id: {
S: 'i-abc1234'
}
}
}

请注意,值的键是类型的前缀,S 代表StringN 代表Number 有没有办法删除这个“类型键”?

最佳答案

以下是使用 DocumentClient 的示例代码。

var AWS = require("aws-sdk");

var creds = new AWS.Credentials('akid', 'secret', 'session');

AWS.config.update({
region : "us-west-2",
endpoint : "http://localhost:8000",
credentials : creds
});

var docClient = new AWS.DynamoDB.DocumentClient();

var table = "Movies";

var year_val = 2015;
var title = "The Big New Movie";

var params = {
TableName : table,
KeyConditionExpression : 'yearkey = :hkey and title = :rkey',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title
}
};

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));
}
});

输出:-

输出没有属性的数据类型。

GetItem succeeded: {
"Items": [
{
"title": "The Big New Movie",
"yearkey": 2015,
"info": {
"rating": 0,
"plot": "Nothing happens at all."
}
}
],
"Count": 1,
"ScannedCount": 1
}

关于node.js - 如何重新格式化来自 Node.js 客户端的 DynamoDB 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39884121/

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