从dynamodb的地图中获取特定元素?

时间:2018-07-24 18:06:56

标签: node.js amazon-dynamodb aws-sdk

我想从我的dynamodb表(即Test)中检索特定的Map元素。 我的数据如下:

[  
{
       "title": "US"
       "info":{
        "name": "State",
        "b": "value",
        "c": "Storyline",
        "d": { "one": 3, "two": 1, "three": 7, "seven": 4 },
        "e":
          "Decription"
          }
      },
     {
       "title": "London"
       "info":{
        "name": "State",
        "b": "value",
        "c": "Storyline",
        "d": { "one": 3, "two": 1, "three": 7, "seven": 4 },
        "e":
          "Decription"
          }
      }
]

我使用了以下代码

var AWS = require("aws-sdk");
AWS.config.update({
    region: "regionname",
    endpoint: "dynamodb.amazon.com"
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "Test";
var title = "US";
var params = {
 TableName: table,
 Key:{
 "title": title
 },
 "ProjectionExpression": "info.d.one" -->Want to go into `info map` and into `d map` and get one value (i.e.3)
};
docClient.get(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));
 }
});

输出它显示像这样的空数据

C:\Nosql\Dynamo>node Read.js
GetItem succeeded: {
  "Item": {}
}

但是当我保留"ProjectionExpression": "title"时,它工作正常。 如何使用node.js API在dynamodb中获取特定的地图元素值?

感谢您的帮助。

谢谢

0 个答案:

没有答案