简体   繁体   English

DynamoDB - putItem - 具有嵌套数据类型的Map(NodeJS,aws-sdk)

[英]DynamoDB - putItem - Map with nested data types (NodeJS, aws-sdk)

All - I am working on a specific business requirement and with the lack of info on Google I thought I would stop here for some info: 全部 - 我正在制定一项特定的业务要求,而且Google上缺少信息,我想我会在这里停下来获取一些信息:

I am basically ingesting a CSV, converting it to a JSON Object and stuffing it into Dynamo. 我基本上是在提取CSV,将其转换为JSON对象并将其填充到Dynamo中。 The interesting part is, the data types of the row values jump between strings and numbers but I am unable to get this to work properly. 有趣的是,行值的数据类型在字符串和数字之间跳转,但我无法使其正常工作。

I am using Node and the aws-sdk and literally used the Amazon Docs to test this straight up and it still did not work, see below: 我正在使用Node和aws-sdk并逐字地使用亚马逊文档对此进行直接测试,但仍然无效,请参阅下文:

var params = {
    TableName: foo,
    Item: {
        masterReportsUuid: uuidv4(),
        reportDate: _eventDate,
        "testAttribute": {
            "Name": {
                "S": "Joe"
            },
            "Age": {
                "N": "35"
            }
        },
    }
};



dbDocClient.put(params, (err, data) => {
    if (err) {
        //log to CloudWatch
        console.log(err);
        reject(err);
    } else {
        resolve(data);
    }
});

The testAttribute obviously is a Map with Name and Age, string and number. testAttribute显然是一个包含Name和Age,字符串和数字的Map。 This is straight from the documentation - 这直接来自文档 -

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#putItem-property

An attribute of type Map. Map类型的属性。 For example: 例如:

"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} “M”:{“姓名”:{“S”:“Joe”},“年龄”:{“N”:“35”}}

But this outputs like this in Dynamo - 但这在Dynamo中输出如下 -

Dynamo Output 发电机输出

So my question is - why is this not working? 所以我的问题是 - 为什么这不起作用?

EDIT: Typos. 编辑:错别字。

Ugh - I fixed the issue. 呃 - 我解决了这个问题。 I will leave this here in case anyone runs into this. 如果有人碰到这个,我会留在这里。

Two Issues - I was using the DynamoDB.DoucmentClient().put API Call and not the DynamoDB.putItem call AND my params object was close but not correct. 两个问题 - 我正在使用DynamoDB.DoucmentClient()。放置API调用而不是DynamoDB.putItem调用AND我的params对象是关闭但不正确。 Please see below for a working example of nested Map AttributeTypes - 请参阅下面的嵌套Map AttributeTypes的工作示例 -

const dbDocClient = new aws.DynamoDB.DocumentClient();
const dbDynamo = new aws.DynamoDB();

var params = {
    TableName: _ReportsTable,
    Item: {
        testUuid: {
            "S": uuidv4()
        },
        testDate: {
            "S": _eventDate
        },
        testAttribute: {
            "M": {
                "Name": {
                    "S": "Joe"
                },
                "Age": {
                    "N": "35"
                }
            }
        },
    }
};


dbDynamo.putItem(params, (err, data) => {
    if (err) {
        //log to CloudWatch
        console.log(err);
        reject(err);
    } else {
        resolve(data);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM