Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何从nodejs客户端重新格式化DynamoDB响应_Node.js_Amazon Dynamodb - Fatal编程技术网

Node.js 如何从nodejs客户端重新格式化DynamoDB响应

Node.js 如何从nodejs客户端重新格式化DynamoDB响应,node.js,amazon-dynamodb,Node.js,Amazon Dynamodb,当我使用aws nodejs客户端从dynamoDB发出get请求时,结果包含一个以类型为键的响应,即 { Item: { newrelic_id: { S: 'nr-1234' } , jumpcloud_id: { S: 'j-234' } , microtime: { N: '1475690490854'

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

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

请注意,值的键是类型的前缀,
S
用于
String
N
用于
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
}

我建议改用DocumentClient,因为它会自动为您转换所有这些内容<代码>新建AWS.DynamoDB.DocumentClient()